Sponsored Content
Top Forums UNIX for Dummies Questions & Answers using awk inside bash script? Post 302505282 by Corona688 on Wednesday 16th of March 2011 03:08:44 PM
Old 03-16-2011
Quote:
Originally Posted by xaiu
Thanks for the tips!

Using epoch time is very intriguing because it avoids a lot of the pain of converting back and forth between HH:MM:SS and seconds, but I'm having trouble setting the system time with date and using epoch time. Any reason to use date over systemsetup?
For one thing, you'll find GNU date in Linux as well as OSX. For another thing, I'm guessing that date is a less heavyweight utility than systemsetup.

To get epoch seconds from GNU date, you just do date +%s

To set the date with epoch seconds, I think you do date -s @192342... where 192342... is your epoch seconds of course and @ tells date that it's epoch seconds. Just one of the little things you have to dig real deep into date's info files to find.

---------- Post updated at 01:08 PM ---------- Previous update was at 01:05 PM ----------

Quote:
Originally Posted by xaiu
Earlier in the script I used IFS=":" to parse HH MM SS from systemsetup -gettime. I unset IFS after grabing my init values and everything seems to be working just fine.
You can set IFS for individual lines and nothing else by prefixing the line. Like: IFS=":" read HH MM SS < datafile Though IFS of course can have side-effects on how parameters expand so be careful what you put on the right-hand side.

You can also use IFS to seperate things into arrays for you.

Code:
OLDIFS="${IFS}"
IFS=":"
ARRAY=( ${SOMETHING_WITH_COLONS_IN_IT} )
IFS="${OLDIFS}"

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed inside bash script - accessing multiple files

I have a file (email) containing email addresses. I have a second file (terms) that contains simple regular expressions and words/characters. Here are some examples: \.trainee \.group \.web I want to go through email and delete lines containing the expressions/words from terms and write... (1 Reply)
Discussion started by: manouche
1 Replies

2. Shell Programming and Scripting

running bash command inside awk

Org file 192.168.1.10 d:\adir\xdir 192.168.1.11 d:\bdir\ydir want to covert it into robocopy \\192.168.1.10\d$\adir\xdir\log* some_localdir\adir robocopy \\192.168.1.10\d$\adir\ydir\log* some_localdir\bbdir (5 Replies)
Discussion started by: ydk
5 Replies

3. 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

4. Shell Programming and Scripting

Why commands inside bash script lost effectiveness?

Hi, I have a bash script to run many system commands on CentOS machine, but I am puzzled by some commands had no effect on parent environment. For example, I want to refresh the desktop xdg menu when some processes added or deleted items from desktop xdg menu. If I run "killall gnome-panel"... (4 Replies)
Discussion started by: hce
4 Replies

5. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

6. Shell Programming and Scripting

Run bash command inside zsh script

Hi, I would like to run following code in bash inside a zsh script. (In this case is output unfortunately very different if you run it in zsh). I tried to put "bash" in front of the code but I obtained following error message "bash: do: No such file or directory " eve though I merged the whole... (7 Replies)
Discussion started by: kamcamonty
7 Replies

7. Shell Programming and Scripting

Is it possible to change paths inside a bash script?

i have some script with some paths inside it. The idea is to some files which is on desktop copy and move to another location. Problem is that inside script is similar to this: cp test1.zip /root/help/ because I allways have another zip files, does it possible to have some input which ask me... (18 Replies)
Discussion started by: tomislav91
18 Replies

8. Shell Programming and Scripting

Aliases NOT working inside bash shell script

i have defined a function ln_s() for customizing the ln command in script1.sh. more script1.sh echo "Starting Execution" ./script2.sh echo "End of Execution" ln_s(){ ] && return ln -s "$1" "$2" } My script1.sh executes another script2.sh which has the following entry more script2.sh... (12 Replies)
Discussion started by: mohtashims
12 Replies

9. Shell Programming and Scripting

Need Multiple checks inside if condition in a bash shell script

Hi, I need to perform the untar and rm operation if the file found is a .tar and does not have test.tar or hello.tar as the file names. Below is the loop to check the same. for tf in *.tar do if ] then found=1 ... (1 Reply)
Discussion started by: mohtashims
1 Replies

10. Shell Programming and Scripting

Executing sed command inside a bash script

I want to run commands inside a bash script. An example is I want to pass the command in a string as regexp as an argument to the script, then run sed on the bash variable sed.sh regexp sed.sh "-i \"s/<p>//g\"" then call sed "$regexp" $fl (3 Replies)
Discussion started by: Kangol
3 Replies
All times are GMT -4. The time now is 05:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy