Facing issues with shell script changes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Facing issues with shell script changes
# 1  
Old 11-22-2018
Facing issues with shell script changes

My current requirement is to replace xxyxx string with value of date

date1 variable holds a date

and the current script writes html tags to a file as follows

Code:
 echo date1
  nawk 'BEGIN{
  FS=","
  print "<HTML>""<HEAD>""<p>Hi All,<br><br>There are no cases closed on the xxyxx"
  print  "that meet the criteria for submission.</p>"
  }
  END{
  print "<p>Regards,<br>Application Team</p></BODY></HTML>"
  }
  ' /u001/Scripts/abc.txt > /u001/Scripts/abc.html

I have tried like this as follows,

Code:
gawk -i inplace 'NR==1{gsub(/xxyxx/,"$$date1")};1' /u001/Scripts/abc.html

I am getting search string replaced as $$date1 instead I want value of date1

and the following sed command is not working

Code:
sed -i 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html

Moderator's Comments:
Mod Comment Added code tags and deleted duplicate post.
# 2  
Old 11-22-2018
Basically never use options like -i as they have lots of unfortunate side effects, like changing file ownerships and permissions besides destroying your original input if anything goes wrong. It's not worth it just to make a pretty one-liner.

Code:
awk 'NR==1 { sub(OLD, NEW); }; 1' OLD="xxyxx" NEW="XXYXX" inputfile > outputfile
# Uncomment these once you've tested awk does what you want.
# cat outputfile > inputfile
# rm -f outputfile


Last edited by Corona688; 11-22-2018 at 11:46 AM..
# 3  
Old 11-23-2018
A few further comments:
- As you don't use any awk feature in your sample code, why use it at all? A shell "here document" might be way more efficient leading to the same result.
- IF you insist on awk, why run it twice in lieu of putting it all into one script?
- Look into awk's man page to find out about how to pass variables / parameters into it.
- The $$ will lead you nowhere in awk, and yield the process ID in (most) shells.
- Your output will be missing the </HEAD> closing tag, and the <BODY> opening one.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Facing issues with rsync

Hello Gurus, I am running rsync command to copy certain Directories and files into that directories to remote server. While ruuning the command all teh files has been copied but I am facing error. The below command I am executing to copy Directories and files to remote server: rsync -avrz ssh... (3 Replies)
Discussion started by: pokhraj_d
3 Replies

2. Post Here to Contact Site Administrators and Moderators

Regarding facing issues while accessing UNIX.com site

Hello Moderators/Admins, This is regarding an issue which I am facing from last 7 to 8 days. Issue is while trying to access this forum(simple hitting http://unix.com) I am able to login but many times my request gets timed out or 404 error or if I am able to login it will be excessive slow even... (0 Replies)
Discussion started by: RavinderSingh13
0 Replies

3. Shell Programming and Scripting

Facing issues with cronjobs

Hello Everyone, We have a cronjob scheduled to pick up files from one system and transfer to another system. the underlying code is a shell script. These cronjobs were working correctly until sometime. 2 days back they did not pick up the scripts but created empty logs. However when we tried... (6 Replies)
Discussion started by: Rads
6 Replies

4. Shell Programming and Scripting

Facing issues with Content-Type:application/x-download Content-Disposition:attachment

I am in the process of developing a perl cgi page. I had succeeded in developing the page but there are few errors/issues with the page. description about cgi page: My CGI page retrieves all the file names from an directory and displays the files in drop down menu for downloading the... (5 Replies)
Discussion started by: scriptscript
5 Replies

5. Shell Programming and Scripting

Shell Script execution issues

Hi, There's a shell script by name "download", which has been created as user "mgr" and that script needs to executed as user "dev". I tried giving privileges 701 on the script download. But it's throwing the error message bin]$ ./download /bin/bash: ./download: Permission denied ... (6 Replies)
Discussion started by: venkatesh17
6 Replies

6. UNIX for Dummies Questions & Answers

Facing issues while running a cronjob !

Hi, I am trying to run a cronjob. But while doing so I am getting the following error message :- can't open yourfile in /var/spool/cron/crontabs directory. No such file or directory How can I resolve this issue ? Please help. Thanks Please view this code tag video for... (14 Replies)
Discussion started by: acidburn_007
14 Replies

7. Shell Programming and Scripting

Facing issues with tar and gzip !

Hi, I am trying to :- (1.) Tar the file and then (2.) Gzip it ! Tar command :- tar -cvf BLUESTAR_Archive.log_$(date +%y_%m_%d_%H_%M).tar /app/local/XXX/XXX/XXX/logs Gzip command :- Gzip /app/local/XXX/XXX/XXX/logs/BLUESTAR_Archive.log_$(date +%y_%m_%d_%H_%M).tar ... (9 Replies)
Discussion started by: acidburn_007
9 Replies

8. Shell Programming and Scripting

Facing problem in the sqlldr & shell script

Guys i am facing two problems : (1) when i create the sql loader file the date format i m getting is this 28-DEC-11 12.03.14.107137 AM; for this i m using this script but unable to load the files trailing nullcols ( SERIALNO, AMOUNT, CLASS, MDN, VDATE "to_date(:TIMESTAMP, 'DD-MON-YY... (6 Replies)
Discussion started by: xal_kaushi
6 Replies

9. Shell Programming and Scripting

facing problem in starting a process in background using shell script.

hey all, i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
Discussion started by: dtomar
8 Replies

10. Shell Programming and Scripting

Facing issue in Solaris OS in crontab for running shell script

Hello i have a shell script. it is running fine when i manually run at command prompt using following command ./script_file but while running shell script from crontab, it is giving error in each line. (2 Replies)
Discussion started by: mabrar
2 Replies
Login or Register to Ask a Question