Find the answer to your Linux question:
Results 1 to 3 of 3
Hi World, I am extracting text from an ebcdic header using dd in the cygwin environment (bash/ksh) as below in order to rename the file to something intelligent. I'm using ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2007
    Posts
    27

    Post Find string and return next string in bash


    Hi World,

    I am extracting text from an ebcdic header using dd in the cygwin environment (bash/ksh) as below in order to rename the file to something intelligent.

    I'm using a specific string position here ($10) but the text I extract is sometimes in a different position in the header so I need to search for preceding text "LINE:" and then extract the next string, which is the info I'm interested in.

    So - using awk or sed (or perl if need be) can anyone help me with the syntax for
    'find string 'LINE:' and return next string'

    Secondly, in order to avoid overwriting files I'm appending a -1, -2, -3 etc but doing a specific search for this.
    In awk, how does one read a filename, check to see if there's a -x at the end, and if so, split that off and increment it by one for naming the next file.

    for file in s*.00* ;
    do
    dd if=$file of=header conv=ascii count=1
    linename=`awk '{print $10}' header`

    if [ ! -e $linename".sgy" ] ; then
    cp $file $linename".sgy"

    elif [ -e $linename".sgy" ] && [ ! -e $linename"-1.sgy" ] ; then
    cp $file $linename"-1.sgy"

    etc until $linename"-4.sgy"

    done

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    So - using awk or sed (or perl if need be) can anyone help me with the syntax for
    'find string 'LINE:' and return next string'
    This is simple with awk. Observe:
    Code:
    [hector@troy ~]$ cat data-file 
    stuff stuff
    LINE: 
    print me #1 
    stuff
    stuff stuff
    LINE:
    print me #2
    stuff
    [hector@troy ~]$ awk '/LINE:/{ getline; print; }' data-file 
    print me #1 
    print me #2

  3. #3
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Secondly, in order to avoid overwriting files I'm appending a -1, -2, -3 etc but doing a specific search for this.
    In awk, how does one read a filename, check to see if there's a -x at the end, and if so, split that off and increment it by one for naming the next file.
    I think I follow what you're asking, but maybe you could post a couple real examples of what you're trying to do.

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •