Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-27-2012, 12:56 AM
|
#1
|
Member
Registered: Dec 2012
Posts: 40
Rep: 
|
help me
awk cat file.txt :
1|34|2012.12.01 00:08:35|12|4|921-*203-0000000000-962797807950|mar0101|0|00000106829DAE7F3FAB187550B920530C00|0|0|4000018001000002||962797807950|||||-1|||||-1||-1|0||||0||||||-1|-1|||-1|0|-1|-1|-1|2012.12.01 00:08:35|1|0||-1|1|||||||||||||0|0|||472|0|12|-2147483648|-2147483648|-2147483648|-2147483648|||||||||||||||||||||||||0|||0||1|6|252|tid{111211344662580792}pfid{10}gob{1}rid{globitel} afid{}uid1{962797807950}aid1{1}ar1{100}uid2{globitel}aid2{-1}pid{1234}pur{!GDRC RESERVE AMOUNT 10000}ratinf{}rec{0}rots{0}tda{}mid{}exd{0}reqa{100}ctr{StaffLine}ftksn{JMT}ftksr{0001}ftktp{PayCall Ticket}||
hi alla i have this this file and i want to print the word "staffline" or any word in this brace "ctr{word}"
always ctr and brace and any word im want to print this word bye use substr function in awk
i try:
awk '{comp[substr["ctr",0]{print}}'
|
|
|
12-27-2012, 01:04 AM
|
#2
|
Member
Registered: Dec 2012
Posts: 40
Original Poster
Rep: 
|
oh my god how
|
|
|
12-27-2012, 01:58 AM
|
#3
|
Member
Registered: Jul 2004
Location: Chennai, India
Posts: 952
|
Search for the pattern /ctr{StaffLine}/. If the line contains this, then print it (not the line but the pattern).
If this is what you want, in the selected line, find out where the string sarts and THEN use substr.
OK
---------- Post added 12-27-12 at 01:28 PM ----------
Search for the pattern /ctr{StaffLine}/. If the line contains this, then print it (not the line but the pattern).
If this is what you want, in the selected line, find out where the string sarts and THEN use substr.
OK
|
|
|
12-27-2012, 02:01 AM
|
#4
|
Member
Registered: Dec 2012
Posts: 40
Original Poster
Rep: 
|
thaaanks
i want to print the word btween { }
"staffline " was just as example
any word
|
|
|
12-27-2012, 02:24 AM
|
#5
|
Member
Registered: Dec 2012
Posts: 40
Original Poster
Rep: 
|
how ?
|
|
|
12-27-2012, 04:19 AM
|
#6
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
|
@eyagh
1. Don't double-post. Post your question only in one place.
2. Why are you insisting on the substr() function? A usually approach is find the best tool for the job, not do everything with one tool. As I posted in your other thread, sed might work better in this particular case.
http://www.linuxquestions.org/questi...lp-4175443087/
|
|
1 members found this post helpful.
|
12-27-2012, 04:25 AM
|
#7
|
Member
Registered: Dec 2012
Posts: 40
Original Poster
Rep: 
|
ok i'm so sorry
ok forget substr but your dont work if we have many "ctr{word} " two or three
hint: we have many "ctr{word} " and i want to count the same word and print the count for each
|
|
|
12-27-2012, 06:31 AM
|
#8
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
|
|
|
All times are GMT -5. The time now is 09:37 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|