AWk is still puzzling me...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWk is still puzzling me...
# 1  
Old 02-07-2002
Java AWk is still puzzling me...

Hi all. Here's what i want to do:
my_first_file
#!/usr/bin/ksh
# BLA BLA BLA BLA
printf "this is my first file \n"
echo " I understand this far"

printf "the day's over \n"
echo "great"

my_second_file
#!/usr/bin/ksh
# BLA BLA BLA BLA
printf "this is my first file \n"
AN_INSERTED_LINE
"blank line"
echo " I understand this far"

printf "the day's over \n"
THE_SAME_INSERTED_LINE
"blank line"
echo "great"



How am i supposed to do to insert the INSERTED_LINE and a blank line between the printf and the echo statement?

Thanx for help
penguin-friend
# 2  
Old 02-07-2002
Re: AWk is still puzzling me...

Penguin-friend,

Just execute following awk command.

awk ' $1~/#/ {print $_};$1 ~/printf/ {print $_ ;print "INSERT_LINE";printf "\n" };$1~/echo/ {print $_}' first_file > second_file

You can use your own line in place of "INSERT_LINE".
first_file is a file in which you want to insert "INSERT_LINE" and blank line.
second_file is your required output file.
I tried and it worked !!!

J1yant
# 3  
Old 02-08-2002
Thanx alot

Well, that was easy, thanx!
penguin-friend
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

3. UNIX for Dummies Questions & Answers

Puzzling permission issue

I have a file, the long listing output by 'ls -l' is -rw-r--r-- 1 usera agroup 1246 Jul 7 14:44 temp.R The file is under a Solaris ZFS file system. As a different user (userb), I did cp temp.R /tmp ls -l /tmp/temp.R -rw-r--r-- 1 userb agroup 1246 Nov 16 14:45 /tmp/temp.R ... (14 Replies)
Discussion started by: nugulus
14 Replies

4. Shell Programming and Scripting

special grep on log files... puzzling me.

Okay, guys, I've got one: I've got a script that formats all of the messages in a log file. It works on a completely verbose method. I'm trying to write a filter that will search for a bunch of case-insensitive strings, but also, always print the first 2 lines. Here's the egrep part: ... (4 Replies)
Discussion started by: quirkasaurus
4 Replies

5. Programming

Linux System C headers puzzling

I am new to Linux system programming, and I found the sophisiticated definition of some library function differ a lot with what I learnt in classes. Here is the question: what does the suffix of function `chmod' in sys/stat.h mean. The funtion claimation is like following: extern int... (5 Replies)
Discussion started by: JackCrital2005
5 Replies

6. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

7. IP Networking

Puzzling Traceroute output

This is the output that I get every so often when trying to do a traceroute to the web server whenever it's inaccessible: traceroute to 64.40.98.181 (64.40.98.181), 30 hops max, 40 byte packets 1 207.97.207.194 (207.97.207.194) 2.625 ms 2.840 ms 2.968 ms 2 core1-5.iad1.rackspace.com... (6 Replies)
Discussion started by: gaspol
6 Replies

8. Shell Programming and Scripting

Syntax error, puzzling

I am just learning over here unix scripting and the OS in general. I wrote this script (with some great help from you guys here) when I test at my desktop with cygwin it works fine, but when I take it to work and try it on the Solaris 2 system there I get an error on line 4 syntax error... (4 Replies)
Discussion started by: Fred Goldman
4 Replies

9. Shell Programming and Scripting

Puzzling Problem: Going back to the previous directory

Hi, I am trying to figure out if there is a way to make linux take me back to the previous directory I was working in. For instance, I am in /home/username/directory1 Then if I cd into /home/username/directory1/temp1/temp2/temp3 I would like to immediately go back to the previous... (2 Replies)
Discussion started by: Legend986
2 Replies

10. Shell Programming and Scripting

puzzling regexp

hey guys, i'm having some problems with my understanding of this whole regexp thing. I'm just exploring here really by trying to do various match & filter & print stuff on the console. I figured i want to get the IP of an interface. So my idea here was that first i filter to extract only... (4 Replies)
Discussion started by: jad
4 Replies
Login or Register to Ask a Question