awk new line rightmost

Hi All

i have a file say test with the following output

vserver    share-name                   path                                          acl
test         test                       test                                       "test/Read",
"test/write"

Expecting the below output

vserver    share-name                   path                                          acl
test         test                       test                                   "test/Read",
                                                                               "test/write"

Hello venkitesh,

Your requirement is not clear, like how you want to check where and which line/text we need to print with whose width long? As per your sample Input_file only I have written following.

awk 'NR==2{match($0,/.[^"]*/);num=length(substr($0,RSTART,RLENGTH));print;next} NR==3{printf("%"num"s%s\n",s1,$0);next} 1' s1=" "   Input_file

Output will be as follows.

vserver    share-name                   path                                          acl
test         test                       test                                       "test/Read",
                                                                                   "test/write"

Above code checks for line number#2 and then checks for the length from where "test/Read" starts then it looks for 3rd line and prints those many spaces. So be careful it will work only for this shown Input_file samples if you have more requirements then show us more sample Input_file, specially with all the rules and regulations with expected sample output.

Thanks,
R. Singh

May I presume an answer like "Open file in a text editor like vi, go to the relevant line, push the <TAB> key n times, write & close the file" were NOT heartily embraced?

So - please develop the habit to post enough context to enable the volunteers in here to start thinking about your request.
In this case: How is that file produced, can the producing application be adapted, are there more or just one occurrence of those problematic lines, how many fields does each line have, what be the field separator, are there other lines having one single field only that should NOT be modified, etc.

Hi ,

sorry for not mentioning enough input.

i have attached a notepad with expected and actual results.

Kindly help

Regards
venkitesh

By giving us a DOS format notepad instead of a UNIX text file are you saying that your input is a DOS format file and you want DOS format output (CR/NL as line separators with no terminator at the end of the last line instead of UNIX text files with NL as line terminators)?

You still have not given us any description at all of what input you are reading to produce either of the output files you have shown us (you have shown us actual output and expected output, but no input). How do you expect us to be able to help you transform the input you will be reading to produce the output you want if we have to guess at what the input might be???

From the 2nd header line of your actual output (which does not appear in your expected output), are we to assume that all fields are fixed width and that the ACL output that you are trying to produce and align is to appear starting in column 91 (even though none of your actual or expected output is aligned that way)?

Please help us help you! Give us:

  1. a clear English description of the format of the input you will be processing,
  2. a clear English description of the format of the output you hope to produce,
  3. a sample input file in that format, and
  4. a sample output file showing the exact output that should be produced when processing that sample input file.

Hi

i am writing a bash script and redirecting the output in a file say test.

The output of test file has four columns.

vserver share-name path acl.

Issue is the values in acl filed is so long that it is coming in new line under vserver filed.

for Eg like this

vserver    share-name                   path                                              acl                                                                           
---------- ---------------------------- ------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------
                                                                                                                                                                                                                               TEST_VS0 TEST_Backup /TEST_CIFS_03/TESTSETUP "TEST\P67564 / Read","TEST\TEST_Manufacturing_TEST_R / Read","TEST\TEST_Backup_RW / Change"

what i am looking for is to print the output in a new line which are comma seperated under the acl field itself.

awk 'NR==2{match($0,/.[^"]*/);num=length(substr($0,RSTART,RLENGTH));print;next} NR==3{printf("%"num"s%s\n",s1,$0);next} 1' s1=" "   Input_file

The above mentioned code works perfectly for the inupt which i provided earlier. But not working for the ones which i posted in this.

Kindly help.

---------- Post updated at 10:45 AM ---------- Previous update was at 10:42 AM ----------

vserver    share-name                   path                                              acl                                                                           
---------- ---------------------------- ------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------
                                                                                                                                                                                                                             TEST_S0 Backup /VOL_03/ring "al\12a / Read","al\ring_Backup_R / Read","al\ring_Backup_RW / Change"