Add strings to test lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add strings to test lines
# 1  
Old 02-25-2013
Add strings to test lines

Hi all,

i have a file that looks like this;
Code:
8120 ahdmesb:8001
8330 ahdmesb:8001
8888 vfnla88s-z2:8888
9060 ahdesb:80
9063 ahdesb:80
9070 nleaip-vip:9070
9090 nleaip-vip:9070
9123 nleaip-vip:9080

i want it to be displayed as:
Code:
ahdmesb:8001 is listening on port 8120
ahdmesb:8001 is listening on port 8330 
vfnla88s-z2:8888 is listening on port 8888 
ahdesb:80 is listening on port 9060 
ahdesb:80 is listening on port 9063 
nleaip-vip:9070 is listening on port 9070 
nleaip-vip:9070 is listening on port 9090 
nleaip-vip:9080 is listening on port 9123


this is reversing the fields order and adding test into lines

thanks in advance Smilie
Eman

Last edited by Franklin52; 02-25-2013 at 09:08 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 02-25-2013
Code:
awk '{ print $2 " is listening on port " $1 } ' filename

# 3  
Old 02-25-2013
try this

Code:
awk  '{print $2 , "is listening on port",   $1}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search a file for certain strings and add them to the end of certain lines

I have a log file which lists groups and users in the following format GROUP1 user1 user2 user3 GROUP2 user4 user5 user6 GROUP3 user7 user8 I need to change the format to: user1|GROUP1 user2|GROUP1 user3|GROUP1 user4|GROUP2 (3 Replies)
Discussion started by: Angela S
3 Replies

2. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

3. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

4. Shell Programming and Scripting

Long lines in test.awk

I have a awk script called test.awk which I run using awk -f test.awk file1.txt > file2.txt I am doing a long print statement and want to put it in separate lines Do I need a '/' at the end or not????? Should it be like this print... (12 Replies)
Discussion started by: kristinu
12 Replies

5. Shell Programming and Scripting

Extract lines between 2 strings add white space

I'm trying to extract all the lines between 2 strings (including the lines containing the strings) To make the strings unique I need to include white space if possible. I'm not certain how to do that. sed -n '/ string1 /,/string2/p' infile > outfile & (4 Replies)
Discussion started by: dcfargo
4 Replies

6. Shell Programming and Scripting

Find lines containing two strings

How can i find lines which contains two strings (or two charcters) let say "ABC" and "DEF". Line: SEFGWN;BVABCFSDFBDEF (3 Replies)
Discussion started by: ksailesh
3 Replies

7. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

8. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

9. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

10. Shell Programming and Scripting

using AWK see the upper lines and lower lines of the strings??

Hi experts, You cool guys already given me the awk script below- awk '/9366109380/,printed==5 { ++printed; print; }' 2008-09-14.0.log Morever, i have one more things- when i awk 9366109380, i can also see the Upper 3 lines as well as below 5 lines of that string. Line 1.... (3 Replies)
Discussion started by: thepurple
3 Replies
Login or Register to Ask a Question