grouping using sed or awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grouping using sed or awk
# 1  
Old 08-15-2012
grouping using sed or awk

I have below inside a file.
Code:
[server1.domain.com]
11.22.33.44
user1

[server2.domain.com]
11.22.33.55
user2

I need this manipulated as
Code:
alias server1.domain.com='ssh user1@11.22.33.44'
alias server2.domain.com='ssh user2@11.22.33.55'

# 2  
Old 08-15-2012
Try:
Code:
awk '{print "alias " gensub(/[\[\]]/,"","g",$1) "='\''ssh " $3 "@" $2 "'\''" }' FS='\n' RS= file.txt

This User Gave Thanks to mirni For This Post:
# 3  
Old 08-15-2012
mirni last ' missing

EDIT:
Its fine Thanks
# 4  
Old 08-15-2012
not on my system. What are you running? And what version of awk?
This will probably work only with GNU awk.
On Solaris use nawk.
This should be more portable:
Code:
 cat infile.txt | tr -d '[]'  | awk '{print "alias "  "='\''ssh " $3 "@" $2 "'\''" }' FS='\n' RS=

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grouping and Subgrouping using awk

I have a data which looks like 1440993600|L|ABCDEF 1440993600|L|ABCD 1440993601|L|ABCDEF 1440993602|L|ABC 1440993603|L|ABCDE . . . 1441015200|L|AB 1441015200|L|ABC 1441015200|L|ABCDEF So basically, the $1 is epoch date, $2 and $3 is some application data From one if the... (5 Replies)
Discussion started by: hemanty4u
5 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. UNIX for Dummies Questions & Answers

awk Grouping and Subgrouping with Counts

So I have a ton of files, lines in excess of 3 MIL per file. I need to find a solution to find the top 3 products, and then get the top 5 skews with a count of how many times that skew was viewed. This is a sample file, shortened it for readability. Each ROW is counted as view. Here's the... (10 Replies)
Discussion started by: JoshCrosby
10 Replies

4. Shell Programming and Scripting

awk and perl grouping.

Hello folks. After awk, i have decided to start to learn perl, and i need some help. I have following output : 1 a 1 b 2 k 2 f 3 s 3 p Now with awk i get desired output by issuing : awk ' { a = a FS $2 } END { for ( i in a) print i,a }' input 1 a b 2 k f 3 s p Can... (1 Reply)
Discussion started by: Peasant
1 Replies

5. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

6. Shell Programming and Scripting

Grouping sed commands

Hello, would you please help me with why my SED command file is outputting the entire input file instead of only the text that I'm trying to block? cat testfile O 111111111-00 DUE-DATE METHOD: FREQUENCY: O 222222222-00 DUE-DATE METHOD: FREQUENCY: O 333333333-02 DUE-DATE METHOD:... (4 Replies)
Discussion started by: lneedh1
4 Replies

7. Shell Programming and Scripting

awk grouping by name script

Hello I am trying to figure out a script which could group a log file by user names. I worked with awk command and I could trim the log file to: <USER: John Frisbie > /* Thu Aug 06 2009 15:11:45.7974 */ FLOAT GRANT WRITE John Frisbie (500 of 3005 write) <USER: Shawn Sanders > /* Thu Aug 06... (2 Replies)
Discussion started by: Avto
2 Replies

8. Shell Programming and Scripting

SED:: Using variable while grouping

Hi, I have the following script :- #!/bin/csh -f set var="HOST2" sed -e 's/\(.*TRANSFER TO\).*\(usr\)/\1 "$var" \2/' tempFile tempFile contains: STOP TRANSFER TO HOST1 /usr/bin/myscript 1. How to use variable in the above sed command. It replaces with $var... (6 Replies)
Discussion started by: angshuman_ag
6 Replies

9. Shell Programming and Scripting

Grouping using sed/awk ?

I run awk cat $1|awk '{print $6}' and get a lot of results and I want results to group them. For example my result is (o/p is unknown to user) xyz xyz abc pqr xyz pqr etc I wanna group them as xyz=total found 7 abc=total .... pqr= Thank (3 Replies)
Discussion started by: pujansrt
3 Replies

10. Shell Programming and Scripting

gnu sed regex grouping not working?

Hello, from the gnu sed manual, I should be able to do this: `\(REGEXP\)' Groups the inner REGEXP as a whole, this is used to: * Apply postfix operators, like `\(abcd\)*': this will search for zero or more whole sequences of `abcd', while `abcd*' ... (3 Replies)
Discussion started by: Allasso
3 Replies
Login or Register to Ask a Question