Please wrap the output chapters between triple-backticks!
This time I have done it for you.
The strategy is to read line by line.
And find a criterion for a line like 10.111.111.111.
This is to be stored, and appended when printing the following lines.
What do you suggest as a criterion?
Please show your first attempt!
The paste command can only do the same action on all lines.
But you want to treat a line like 10.111.111.111 differently.
Start with grep ing these special lines!
A criterion can be: a space character. grep " " file.txt
That shows one type of lines (where an item is to be appended) grep -v " " file.txt
shows the other lines (the item).
You can use the same in an awk script: awk '/ / { print $0 }' file.txt awk '!/ / { print $0 }' file.txt
Here it seems to be better to test the Number of Fields (NF): awk 'NF > 1 { print $0 }' file.txt awk 'NF == 1 { print $0 }' file.txt
Now, for the one type, you store the line in a variable, and don't print it.
And for the other type, you print the line along with the variable.
The variable is within awk, so you need one invocation of awk.
this command: grep -v " " file.txt
-> result:
10.111.111.111
10.111.111.112
10.111.111.110
10.111.111.99
But I don't know how to get it right with my desired format like this:
--------------->
output:
2 gi1/0/1 adcd.abcd.cdfe 10.111.111.111
4 gi1/0/2 abcd.safa.awrf 10.111.111.111
2 gi1/0/3 gseg.egew.wqfq 10.111.111.111
2 gi1/0/1 afga.gwet.aqgq 10.111.111.112
4 gi1/0/2 asgf.qwfg.gvqr 10111.111.112
2 gi1/0/1 afga.gwet.aqgd 10.111.111.110
4 gi0/28 afga.gwet.aqge 10.111.111.99
If possible, please help me with a complete script.
Thank you very much!
Make sure to read some important stuff in awk manual. You'll have to read some sections quite carefully and experiment a lot, but I bet it will be a great usage of your time to solve this issue.
Make sure you understand: