Web Hosting Talk







View Full Version : Bash Script help


steveks
10-31-2008, 12:18 PM
Bash Script help

Hello Gurus,
Please help me. I have a file which has only one line. But, that line is a very big line just as below.
Now, i need to split this single line to many lines in to the same or another file. please help me.
Code:
cat test
123333333333333333333333333333333333333333333333344444444444444444444444444444455555555555555555555555555555566666666666666666666666666666666666666667 67777777777777777777788888888888888888888888888899999999999999999999999999







__________________
The man who removes a mountain begins by carrying away small stones.






Last edited by bear : 10-31-2008 at 12:34 PM.
Reason: Added code tags

bsddaemon
10-31-2008, 12:29 PM
How do you wanna split that line? At every new number?
Give us an output example.

steveks
10-31-2008, 12:42 PM
my requirement is from 5, 6 it should come in next line.





__________________
The man who removes a mountain begins by carrying away small stones.

bsddaemon
10-31-2008, 01:33 PM
Code:
sed 's/56/5\
6/g' test

steveks
10-31-2008, 02:02 PM
Thanks Bsddaemon. Exactly it worked. Thanks a ton. So, now comes my next request.
Now, i have a file with content as below.
"A" status"unavailable"
"B" status"available"
"C" status"unavailable"
"D" status"unavailable"
"E" status"available"
"F" status"available"
So, now my requirement is that I need a script which should process this file and mail me the service which are unavaliable.
In this case, it should mail me as service acd is unavaliable.
Is this possible using arrays ?





__________________
The man who removes a mountain begins by carrying away small stones.

bsddaemon
10-31-2008, 02:38 PM
No need to use array, you can try, though.
awk could be replaced by cut.
Code:
#!/bin/sh

STATUS=unavailable
FILE=
MAILTO=

unavailServList (){
grep $STATUS $FILE | awk -F \" '{print $2}' | tr -d "\n"
}

UNAVAIL_SERV=$(unavailServList)

if [ "$UNAVAIL_SERV" != "" ]; then
mail -s "Services $UNAVAIL_SERV $STATUS" $MAILTO
fi

exit 0

steveks
10-31-2008, 03:45 PM
bsddaemon,
You are simple great. It worked perfectly,
But, i need to know something.
what does grep $STATUS $FILE | awk -F \" '{print $2}' | tr -d "\n" means ?





__________________
The man who removes a mountain begins by carrying away small stones.

bsddaemon
10-31-2008, 11:22 PM
Well, not that great, I just started learning shell script programming.
Anyway, I think you had better read manual regarding those commands. It will be run by you, so you should understand every single line of it

jem3
11-03-2008, 01:48 PM
Quote:



Originally Posted by steveks


bsddaemon,
You are simple great. It worked perfectly,
But, i need to know something.
what does grep $STATUS $FILE | awk -F \" '{print $2}' | tr -d "\n" means ?


These are variables that are set at top of the script:
STATUS=unavailable
FILE=
MAILTO=
You would put in what the file name is and where you want it mailed to.





__________________
Joyce Miletic RHCT + Systems EngineerNavisite Dedicated Hostinghttp://dedicatedhosting.navisite.com"24/7/365" Myth or Reality? Take the Survey