Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to strip string out of Unix file?

Status
Not open for further replies.

ecnirp

MIS
Nov 26, 2001
2
GB
Hi

I have the following file on Unix where i need to extract the USER=<name> string, eg USER=boma1508 into a seperate file so we can look at the usernames stored in the log :

31-MAY-2004 17:52:23 *
(CONNECT_DATA=(SERVICE_NAME=HRP036A.pb.astra.COM)(CID=(PROGRAM=BUSOBJ.EXE)(HOST=MADWMA31)(USER=boma1508))
) * (ADDRESS=(PROTOCOL=tcp)(HOST=129.214.173.174)(PORT=1134)) * establish * * 0
31-MAY-2004 17:52:39 *
(CONNECT_DATA=(SERVICE_NAME=HORIP036A.pb.astra.COM)(CID=(PROGRAM=BUSOBJ.EXE)(HOST=MADWMA31)(USER=PJC1508))
) * (ADDRESS=(PROTOCOL=tcp)(HOST=129.244.113.174)(PORT=1335)) * establish *
31-MAY-2004 17:59:06 * (CONNECT_DATA=SERVICE_NAME=pb.astra.COM)(CID=PROGRAM=C:\ProgramFiles\Business Objects\Server\B
roadcast Agent 5.0\BcsScdul.exe)(HOST=CGTSAPP220)(USER=SVC_BusObj))) * (ADDRESS=(PROTOCOL=tcp)(HOST=165.15.33.147)(PORT=1192)) * establish * HORP036A.pb.astra.COM * 0
31-MAY-2004 17:59:07 *
(CONNECT_DATA=(SERVICE_NAME=HAORP036A.pb.astra.COM)(CID=(PROGRAM=C:\Program Files\Business Objects\Server\B
roadcast Agent 5.0\BcsScdul.exe)(HOST=CGTSAPP220)(USER=SVC_BusObj))) *
(ADDRESS=(PROTOCOL=tcp)(HOST=125.65.33.147)(PORT=1193)) * establish * HOIRP036A.pb.astra.COM * 0


The USER portion exists at different character postions on each line, and the log has over 50,000 lines, so can anyone recommend a way to achieve this?, the command if possible would be great! I have looked at Vi and sed, but they don't seem to cover this?

Thanks for any help!

 
Try this...

awk 'match($0,"USER=[^)]*"){print substr($0,RSTART,RLENGTH)}' file1
 
not sure if you have wrapped line or not, but here's something to start with.

Code:
sed -e 's!.*\(USER=[^)][^)]*\).*!\1!g' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks Ygor & vgersh99, both methods did the job!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top