awk new line rightmost


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk new line rightmost
# 1  
Old 01-21-2017
awk new line rightmost

Hi All

i have a file say test with the following output

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

Expecting the below output
Code:
vserver    share-name                   path                                          acl
test         test                       test                                   "test/Read",
                                                                               "test/write"

# 2  
Old 01-21-2017
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.
Code:
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.
Code:
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
# 3  
Old 01-21-2017
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.
# 4  
Old 01-21-2017
Hi ,

sorry for not mentioning enough input.

i have attached a notepad with expected and actual results.

Kindly help

Regards
venkitesh
# 5  
Old 01-21-2017
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.
# 6  
Old 01-23-2017
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
Code:
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.

Code:
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 ----------

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

Honey, I broke awk! (duplicate line removal in 30M line 3.7GB csv file)

I have a script that builds a database ~30 million lines, ~3.7 GB .cvs file. After multiple optimzations It takes about 62 min to bring in and parse all the files and used to take 10 min to remove duplicates until I was requested to add another column. I am using the highly optimized awk code: awk... (34 Replies)
Discussion started by: Michael Stora
34 Replies

3. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

4. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

5. Shell Programming and Scripting

increment counter as suffix starting with the rightmost digit

Hi, I would like to add a suffix to a file name but maintain the suffix length to 5 digits. For eg, output > 1st_file.00001, 2nd_file.00002...10th_file.00010....100th_file.00100 Can anyone please advise me on how to go about it? Platform: SunOS mps201a 5.9 Generic_118558-39 sun4u... (7 Replies)
Discussion started by: danish0909
7 Replies

6. Shell Programming and Scripting

Counting rows line by line from a specific column using Awk

Dear UNIX community, I would like to to count characters from a specific row and have them displayed line-by-line. I have a file called testAwk2.csv which contain the following data: rabbit penguin goat giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
Discussion started by: vnayak
4 Replies

7. Shell Programming and Scripting

How to calculate mean in AWK? line by line several files, thousands of lines

I'm kinda stuck on this one, I have 7 files with 30.000 lines/file like this 050 0.023 0.504336 050 0.024 0.529521 050 0.025 0.538908 050 0.026 0.537035 I want to find the mean line by line of the third column from the files named like this: Stat-f-1.dat .... Stat-f-7.dat Stat-s-1.dat... (8 Replies)
Discussion started by: AriasFco
8 Replies

8. Shell Programming and Scripting

awk script to move a line after the matched pattern line

I have the following text format in a file which lists the question first and then 5 choices after that the explanantion and finally the answer. 1.The amount of time it takes for most of a worker’s occupational knowledge and skills to become obsolete has been declining because of the... (2 Replies)
Discussion started by: nanchil_guy
2 Replies

9. Shell Programming and Scripting

reading a file inside awk and processing line by line

Hi Sorry to multipost. I am opening the new thread because the earlier threads head was misleading to my current doubt. and i am stuck. list=`cat /u/Test/programs`; psg "ServTest" | awk -v listawk=$list '{ cmd_name=($5 ~ /^/)? $9:$8 for(pgmname in listawk) ... (6 Replies)
Discussion started by: Anteus
6 Replies

10. Shell Programming and Scripting

Awk not working due to missing new line character at last line of file

Hi, My awk program is failing. I figured out using command od -c filename that the last line of the file doesnt end with a new line character. Mine is an automated process because of this data is missing. How do i handle this? I want to append new line character at the end of last... (2 Replies)
Discussion started by: pinnacle
2 Replies
Login or Register to Ask a Question