Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:30:57+00:00 2026-05-27T17:30:57+00:00

Given a file with data like this (ie stores.dat file) id storeNo type 2ttfgdhdfgh

  • 0

Given a file with data like this (ie stores.dat file)

id               storeNo     type
2ttfgdhdfgh      1gfdkl-28   kgdl
9dhfdhfdfh       2t-33gdm    dgjkfndkgf

Desired output:

id               |storeNo     |type
2ttfgdhdfgh      |1gfdkl-28   |kgdl
9dhfdhfdfh       |2t-33gdm    |dgjkfndkgf

Would like to add a “|” delimiter between each of these 3 cut ranges:

cut -c1-18,19-30,31-40 stores.dat

What is the syntax to insert a delimiter between each cut?

BONUS pts (if you can provide the option to trim the values like so):

id|storeNo|type
2ttfgdhdfgh|1gfdkl-28|kgdl
9dhfdhfdfh|2t-33gdm|dgjkfndkgf\

UPDATE (thanks to Mat’s answer) I ended up with success on this solution – (it is a bit messy but SunOS with my bash version doesn’t seem to support more elegant arithmetic)

#!/bin/bash
unpack=""
filename="$1"
while [ $# -gt 0 ] ; do
    arg="$1"
    if [ "$arg" != "$filename" ]
    then
        firstcharpos=`echo $arg | awk -F"-" '{print $1}'`
        secondcharpos=`echo $arg | awk -F"-" '{print $2}'`
        compute=`(expr $firstcharpos - $secondcharpos)`
        compute=`(expr $compute \* -1 + 1)`
        unpack=$unpack"A"$compute
    fi
    shift
done
perl -ne 'print join("|",unpack("'$unpack'", $_)), "\n";' $filename 

Usage: sh test.sh input_file 1-17 18-29 30-39

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:30:57+00:00Added an answer on May 27, 2026 at 5:30 pm

    If you’re not afraid of using perl, here’s a one-liner:

    $ perl -ne 'print join("|",unpack("A17A12A10", $_)), "\n";' input 
    

    The unpack call will extract one 17 char string, then a 12 char one, then a 10 char one from the input line, and return them in an array (stripping spaces). join adds the |s.

    If you want the input columns to be in x-y format, without writing a “real” script, you could hack it like this (but it’s ugly):

    #!/bin/bash
    unpack=""
    
    while [ $# -gt 1 ] ; do
        arg=$(($1))
        shift
        unpack=$unpack"A"$((-1*$arg+1))
    done
    
    perl -ne 'print join("|",unpack("'$unpack'", $_)), "\n";' $1 
    

    Usage: t.sh 1-17 18-29 30-39 input_file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a file with data like this (ie stores.dat file) sid|storeNo|latitude|longitude 2tt|1|-28.0372000t0|153.42921670 9|2t|-33tt.85t09t0000|15t1.03274200 Desired
Given a file with data like this (ie stores.dat file) sid|storeNo|latitude|longitude 2tt|1|-28.0372000t0|153.42921670 9|2t|-33tt.85t09t0000|15t1.03274200 What
Given a file with data like this (i.e. stores.dat file) sid|storeNo|latitude|longitude 2|1|-28.03720000|153.42921670 9|2|-33.85090000|151.03274200 What
I have a data structure which is as given below: class File { public
Given file names like these: /the/path/foo.txt bar.txt I hope to get: foo bar Why
i want to find the mime-type for a given file extension on an IIS
I wrote this script which counts occurrences of particular pattern in a given file.
Given a FILE*, is it possible to determine the underlying type? That is, is
My data looks like this: 00000000001 : `12341234...12341234' Basically a unique id value associated
I am having a sample file as given below. This is an SQL Loader

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.