Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Shell Scripting

  1. #11
    Join Date
    Sep 2006
    Beans
    8,163
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Shell Scripting

    Quote Originally Posted by rohit verma View Post
    Input ::
    1212||sdfsdfsdf fgkdjfkgljlsdfg||sdfsdf
    4454||"sadfsdfg
    sdfgsdfg
    sdf"||sdfgdfg
    4454||ds gkdkjfhgskjfsdhkjg||sdfsdf


    Output:::
    1212||sdfsdfsdf fgkdjfkgljlsdfg||sdfsdf
    4454||"sadfsdfg sdfgsdfg sdf"||sdfgdfg
    4454||ds gkdkjfhgskjfsdhkjg||sdfsdf
    It's still a guess at precisely what you are trying. But if you want to print out the rows that have numbers in the first column, you can do it with awk

    Code:
    awk -F '\|\|' '$1 ~ /[0-9]+/ {print $0}' < inputfile.txt
    The Truth Shall Make Ye Fret.

  2. #12
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,463
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Shell Scripting

    Code:
    awk -F '\\|\\|' 'NF==3 { x=0; print $0 }
                     NF==1 { printf("%s ", $0); }
                     NF==2 { x++; if( x==2 ) printf("%s\n",$0); else printf("%s ",$0); }' file.txt
    test

    Code:
    $ echo '1212||sdfsdfsdf fgkdjfkgljlsdfg||sdfsdf
    4454||"sadfsdfg
    sdfgsdfg
    sdf"||sdfgdfg
    4454||ds gkdkjfhgskjfsdhkjg||sdfsdf'  | awk -F '\\|\\|' 'NF==3 { x=0; print $0 } NF==1 { printf("%s ", $0); } NF==2 { x++; if( x==2 ) printf("%s\n",$0); else printf("%s ",$0); }'
    
    1212||sdfsdfsdf fgkdjfkgljlsdfg||sdfsdf
    4454||"sadfsdfg sdfgsdfg sdf"||sdfgdfg
    4454||ds gkdkjfhgskjfsdhkjg||sdfsdf
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

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