Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux HostsFree MagazinesJobs
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page AWK Help
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 06-17-2008   #1 (permalink)
Just Joined!
 
Join Date: Jan 2008
Posts: 19
AWK Help

Hi All,

I want to create a script in which i want to fulfill three conditions with awk command.
I want to search from a sentence if there is sel at the end of string, then it append "_aa01", if it has del at end it will append "_bb01", if nothing between both conditions it will append "$DATE"

if i can satisfy these all three conditions without awk, please let me know with examples.

Please help.

Thanks,
Inder Punj
inderPunj is offline   Reply With Quote
Old 06-18-2008   #2 (permalink)
Just Joined!
 
radoulov's Avatar
 
Join Date: Sep 2007
Posts: 84
Please post sample input and an example of the desired output.
radoulov is offline   Reply With Quote
Old 06-18-2008   #3 (permalink)
Just Joined!
 
Join Date: Jan 2008
Posts: 19
The 3 comdition should be as follows :-
1. Let i have inder_eatapple_sel then it will append _aa01 at the end, LIKE - inder_eatapple_sel_aa01
2. If i have inder_eatapple_del then it will append _bb01 at the end LIKE - inder_eatapple_del_bb01
3. if it has not sel nor del at the end, then it append current date.

Please suggest, if want more clearification , please let me know.

Thanks,
Inder
inderPunj is offline   Reply With Quote
Old 06-18-2008   #4 (permalink)
Just Joined!
 
radoulov's Avatar
 
Join Date: Sep 2007
Posts: 84
Yes,
as I said, post sample from the input and example (not description) of the desired output.
radoulov is offline   Reply With Quote
Old 06-22-2008   #5 (permalink)
scm
Linux Engineer
 
Join Date: Feb 2005
Posts: 1,003
Seems a pretty clear statement of the requirement to me.
Code:
awk '
/_sel$/  {print $0 "_aa01"; next}
/_del$/  {print $0 "_bb01"; next}
             {print $0 "_'$(date +%Y%m%d)'"}' inputfile
Adjust the date command to give the format you require (but avoid including slash characters (/)!).
scm is offline   Reply With Quote
Old 06-22-2008   #6 (permalink)
Just Joined!
 
radoulov's Avatar
 
Join Date: Sep 2007
Posts: 84
This should be sufficient:

Code:
awk '
$0=$0"_"(/[sd]el$/?(/_sel$/?"aa":"bb")"01":d)
' d="$(date +%F)" file
Avoid calling the external date command for every matching record ...

I prefer to have an example in/output though ...
radoulov is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
 

Free Magazines
Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe
Systems Management News, the newspaper for IT systems administration and data center managers!
Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe
The Enterprise Newsweekly
eWeek is the essential technology information source for builders of e-business.
subscribe
Oracle Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe
Total Telecom
Total Telecom is "The Economist of the communications industry".
subscribe
More free magazines »



All times are GMT. The time now is 04:42 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.2.0