merging 2 lines with awk and stripping first two words


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers merging 2 lines with awk and stripping first two words
# 1  
Old 10-22-2008
merging 2 lines with awk and stripping first two words

Hey all

i am pretty new to awk... here my problem.

My input is something like this:
type: NSR client;
name: pegasus;
save set: /, /var, /part, /part/part2, /testpartition,
/foo/bar, /what/ever, /stuff;

what i need is a list of all partitions without the "save set:" and without the "," inbetween.
like:
/ /var /part /part/part2 /testpartition /foo/bar /what/ever /stuff
trying to get this.. but somehow.. always got bad results of


thnx
greets
Bazzed
# 2  
Old 10-22-2008
Not nice but works - I bet a more compact version will show up:
Code:
awk 'BEGIN{ORS=" "} /^ *save set:/ { gsub (/([,;]|save set: )/,"",$0); print; getline; gsub (/[,;]/,"",$0); print $0 "\n" }' infile | sed 's/  */ /g'


Last edited by zaxxon; 10-22-2008 at 10:03 AM..
# 3  
Old 10-22-2008
zaxxon thnx a lot for your help.

but somehow i dont get any output.

guess i forgot to tell you that i have some empty "spaces" before "save set:"

looks like:
Code:
            type: NSR client; 
            name: pegasus;
        save set: /, /var, /part, /part/part2, /testpartition,
                  /foo/bar, /what/ever, /stuff;

(i hope the forum will not "eat" the blanks")
# 4  
Old 10-22-2008
If you use [ code ] tags, it won't, as you did already Smilie
Code:
^save set

The ^ is the problem. If you replace it with a blank and an asterix " *", it will work, but then it's getting ugly since the leading spaces are not removed.

Is a solution in sed ok too? I can write it more compact than in awk. Else you might have to wait for other people to post. I also had an error in it - i edited my 1st post.
I added the sed thing at the end to remove the lots of blanks out of the line, occuring by the changed input file.
Output should be ok, but not very compact.

Last edited by zaxxon; 10-22-2008 at 10:05 AM..
# 5  
Old 10-22-2008
How about:

Code:
#  sed -n '/save set/{N;s/^.*save set://p;}' infile | tr -s "\n,;" "   "
 / /var /part /part/part2 /testpartition /foo/bar /what/ever /stuff

bit hacky with the tr, but looks like it's close to what you're after...
# 6  
Old 10-22-2008
Hammer & Screwdriver what about just scripted?

Code:
> cat file285
            type: NSR client; 
            name: pegasus;
        save set: /, /var, /part, /part/part2, /testpartition,
                  /foo/bar, /what/ever, /stuff;

> cat file285 | tr -s " " | tr -d "\n" | cut -d":" -f4
 /, /var, /part, /part/part2, /testpartition, /foo/bar, /what/ever, /stuff;

>

# 7  
Old 10-22-2008
Poster asked for awk, not sure if other tools was ... allowed ;D
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Merging two lines into one (awk)

Hi, I am attempting to merge the following lines which run over two lines using awk. INITIAL OUTPUT 2019 Sep 28 10:47:24.695 hkaet9612 last message repeated 1 time 2019 Sep 28 10:47:24.695 hkaet9612 %ETHPORT-5-IF_DOWN_INTERFACE_REMOVED: Interfa ce Ethernet1/45 is down (Interface removed)... (10 Replies)
Discussion started by: sand1234
10 Replies

2. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

3. Shell Programming and Scripting

Count words/lines between two tags using awk

Is there an efficient awk that can count the number of lines that occur in between two tags. For instance, consider the following text: <s> Hi PP - my VBD - name DT - is NN - . SENT . </s> <s> Her PP - name VBD - is DT - the NN - same WRT - . SENT - </s> I am interested to know... (4 Replies)
Discussion started by: owwow14
4 Replies

4. Shell Programming and Scripting

Merging words splitted into characters with awk

I have an OCR output with some words splitted into single characters separated by blank spaces, and I want the same text with these words written correctly. Example: This is a text w i t h some s p l i t e d W o r d s . The regular expression for matching splitted words could be something... (5 Replies)
Discussion started by: dokamo
5 Replies

5. Shell Programming and Scripting

Swapping lines beginning with certain words using sed/awk

I have a large file which reads like this: fixed-address 192.168.6.6 { hardware ethernet 00:22:64:5b:db:b1; host X; } fixed-address 192.168.6.7 { hardware ethernet 00:22:64:5b:db:b3; host Y; } fixed-address 192.168.6.8 { hardware ethernet 00:22:64:5b:db:b4; host A; }... (4 Replies)
Discussion started by: ksk
4 Replies

6. Shell Programming and Scripting

awk help needed in trying to count lines,words and characters

Hello, i am trying to write a script file in awk which yields me the number of lines,characters and words, i checked it many many times but i am not able to find any mistake in it. Please tell me where i went wrong. BEGIN{ print "Filename Lines Words Chars\n" } { filename=filename + 1... (2 Replies)
Discussion started by: salman4u
2 Replies

7. Shell Programming and Scripting

Urgent help needed on merging lines with similar words

Hi everyone, I need help with a merging problem. Basically, I have a file with several lines (in this example 9 lines) such as: Amie, Jay, Sasha, Rob, Kay Mia, Frank Jay, Nancy, Cecil Paul, Ked, Nancy, 17, Fred 14, 16, 18, 20 9, 11 12, Frank 18, Peter, 62 Nancy, 27 A delimiter is... (3 Replies)
Discussion started by: awb221
3 Replies

8. UNIX for Dummies Questions & Answers

[bash]Stripping lines from a list

Hello! I have a script that is (among other things) doing the following: list=/tmp/list1.txt ncftpls -u <user> -p <password> -x "-l1" server.domain.tld > $list cat $list | nl echo "Choose file: " read file cat /tmp/list1.txt | nl | grep $file | sed -e "s/$file//g" -e "s/ //g" | column -t... (8 Replies)
Discussion started by: noratx
8 Replies

9. Shell Programming and Scripting

Merging lines using AWK

Hi, Anybody help on this. :( I want to merge the line with previous line, if the line starts with 7. Otherwise No change in the line. Example file aa.txt is like below 122122 222222 333333 734834 702923 389898 790909 712345 999999 My output should be written in another file... (6 Replies)
Discussion started by: senthil_is
6 Replies

10. Shell Programming and Scripting

Merging files with AWK filtering and counting lines

Hi there, I have a couple of files I need to merge. I can do a simple merge by concatenating them into one larger file. But then I need to filter the file to get a desired result. The output looks like this: TRNH 0000000010941 ORDH OADR OADR ORDL ENDT 1116399 000000003... (2 Replies)
Discussion started by: Meert
2 Replies
Login or Register to Ask a Question