Problem facing with sed and awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem facing with sed and awk
# 15  
Old 04-10-2008
Thanks era for pointing that out ..its indead a lesson ..
Am still not getting a solution though am working on it
# 16  
Old 04-10-2008
But Franklin's solution will directly put the script to give the output which is not want i need.

1.txt > temp.sh > 2.sh
when 2.sh runs i shud get the output not when temp.sh runs.
I need the solution to be written in temp.sh so that it access 1.txt, replace certain lines and writes to 2.sh. Then am suppose to run 2.sh to get the formatted printing.

franklin's solution directly jumps to the output. i dont get a 2.sh !!!

Hope I made it clear.
# 17  
Old 04-10-2008
Code:
echo 'BEGIN {' >temp.awk
 awk '$1 ~ "column"{gsub(",|\"","");
  printf("printf (\"%%*s\\n\", \"" $2 "\", \"" $3 "\");\n") }' 1.txt >>temp.awk
echo '}' >>temp.awk

This creates an awk script, not a shell script. I'm sure you can figure out how to adapt it if you absolutely want a shell script.
# 18  
Old 04-11-2008
Am still facing problems with this .
Am thinking of another logic.

Keeping the same file format ( I have writeen in bold -- scroll up), can I search for teh patterns "print" and "column" using a single grep (or any other search command ) from teh file 1.txt and write it to "temp.txt"

Thanks
# 19  
Old 04-11-2008
Code:
egrep '(print|column)' 1.txt >temp.txt

# 20  
Old 04-11-2008
Hi,

after using the above command and a bit of tuning i made the file format as below:

print
# Print first some lines #
column 1, "cat",
column 9, rat,
column 56, goat

# this is a comment statement #
print column 46, naming function
print heaven
print hell
print
column 23, market"&&&",
column 30, fill
######
print
column 55, descrition,

Can u help mw to get some variables as below:
var1="print column 1, "cat", column 9, rat, column 56, goat"
var2="print column 46, naming function"
var3="print heaven"
-----
var5="print column 23, market"&&&",column 30, fill"

dont want the comment statements. And i can remove them ..In short,i need to select from the first" print " to the next print(exclude) and store that in a variable.

I can do the storing but cutting is not successful. I tried using awk but that too didnot give the desired o/p

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripting with awk: facing problem

Hi, I wants to print the 9th column information with its path name in some txt file. Here is one line which works fine for me: rfdir /castor/cern.ch/user/s/sudha/forPooja | grep data | awk '{print "rfio:///castor/cern.ch/user/s/sudha/forPooja/"$9}' > dataFilenames.list rfdir=="ls -ltr" ... (2 Replies)
Discussion started by: nrjrasaxena
2 Replies

2. AIX

facing problem using su

Hi, I am able to login using su - or su directly , # prompt is coming, it doesnt ask for password. any normal user on aix system is login using su - or su . Please suggest where to change the configuration direct root login is disabled in /etc/ssh/sshd_config file. (0 Replies)
Discussion started by: manoj.solaris
0 Replies

3. Shell Programming and Scripting

Problem facing in using awk command

Hi., I am not able to replace the string with another string using gsub fn of awk command. My code: awk 'BEGIN gsub(004,IND,004)' p.txt and my i/p file p.txt is of the format: av|004|adkf|Kent,004|s av|005|ssdf|Kd,IT park|s . . . and my desired o/p should be of : (13 Replies)
Discussion started by: av_vinay
13 Replies

4. Solaris

Facing Problem with metaset in SVM

hi all, i am using solaris 5.10 on sun blade 150 and i am trying to configure diskset in sun volume manager. When i fire the following command, it says some rpc related error. bash-3.00# metaset -s kingston -a -h u15_9 metaset: u15_9: metad client create: RPC: Program not registered how to... (4 Replies)
Discussion started by: kingston
4 Replies

5. Shell Programming and Scripting

problem facing in if -else condition

can u plz tell me where is the error echo enter the filename to be searched read fname if #-d $fname then echo file exists if then echo itsa directory elif then echo its readable cat $fname else echo its not readable fi else ... (1 Reply)
Discussion started by: gotam
1 Replies

6. Infrastructure Monitoring

Facing problem while configuring snmp

HI, I am facing these two errors while configuring snmp can any body guide me. vi /var/log/snmpd.log Error opening specified endpoint "udp:161" Server Exiting with code 1 i also tried bash-3.00# netstat -a | grep snm *.snmpd Idle bash-3.00# lsof -i :161 bash: lsof: command not... (2 Replies)
Discussion started by: nir1785
2 Replies

7. Solaris

Facing problem with zone

i am using this way to create zone1 and zone2 bash-2.05b# zonecfg -z zone1 zone1: No such zone configured Use 'create' to begin configuring a new zone. zonecfg:zone1> create zonecfg:zone1> set zonepath=/zone/1 zonecfg:zone1> set autoboot=true zonecfg:zone1> add net zonecfg:zone1:net>... (6 Replies)
Discussion started by: coxmanchester
6 Replies

8. Solaris

please help as i am facing problem with uptime

Hi I am getting the uptime output as follows 12:40am up 4 day(s), 18:29, 2 users, load average: 38.97, 36.54, 34.89 The load average is too high . I have checked the processes , but no process is taking too much cpu time Please help (3 Replies)
Discussion started by: guy009
3 Replies

9. UNIX for Dummies Questions & Answers

facing a problem in redirection

Hi, I am doing this perl script print (@line(1..15)); the lines 1 to 15 get printed... how can i redirect this to file? thanks and regards vivek.s (4 Replies)
Discussion started by: vivekshankar
4 Replies
Login or Register to Ask a Question