LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-30-2011, 12:26 PM   #1
takayama
Member
 
Registered: Sep 2009
Posts: 97

Rep: Reputation: 0
Awk problem


Im doing a scripting project for school and has run into a problem.
I want to search for the occurrence of "[" in a field. And then i want to delete that and everything after that (in that field)
Any tips of howto do it?
 
Old 01-30-2011, 12:33 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Have a look at the awk string functions (sub, gsub and substr in particular).

Hope this helps.
 
1 members found this post helpful.
Old 01-30-2011, 01:04 PM   #3
takayama
Member
 
Registered: Sep 2009
Posts: 97

Original Poster
Rep: Reputation: 0
i just find how to remove speciall numbers
ex
Quote:
awk '{sub("[f", "");print}' apa
dont print [f], but the stuff after [ can change, and i dont want to print [ or anything that is after it.
 
Old 01-30-2011, 05:47 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

This example targets field number 2:
Code:
awk '{ sub("\\[.*","",$2); print $2 }' infile
Hope this helps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[awk] NR problem dhodho Programming 4 08-13-2010 04:31 AM
[SOLVED] awk: how can I assign value to a shell variable inside awk? quanba Programming 6 03-23-2010 02:18 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
Awk Problem - Help Me kalyanofb General 1 02-01-2007 05:12 AM
A problem about awk jackk294 Programming 4 07-13-2006 08:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration