need help with script - output to file, but complicated


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help with script - output to file, but complicated
# 8  
Old 10-27-2008
Quote:
Originally Posted by twoodcc

Code:
...
cat tim | while read LINE
do
if [LINE == "key 0"]; then
...

you need the "this is a variable" indicator, which in shell scripts is a dollar ($) sign. You also need to put a spaces around [ and ].
Also note, when assigning values to a variable, you don't use the dollar sign, only when retrieving values.
Code:
...
cat tim | while read LINE
do
if [ $LINE == "key 0" ]; then
...

# 9  
Old 10-27-2008
Quote:
Originally Posted by wempy
you need the "this is a variable" indicator, which in shell scripts is a dollar ($) sign. You also need to put a spaces around [ and ].
Also note, when assigning values to a variable, you don't use the dollar sign, only when retrieving values.
Code:
...
cat tim | while read LINE
do
if [ $LINE == "key 0" ]; then
...

thanks. i am getting somewhere. here is what i have now:

Code:
#!/bin/bash

output=$(uptime)
length=${#output}

cat tim | while read LINE
do
if [ "${LINE}" == "key 0" ]; then
for ((i=1; i<=length; i++))
do
character=$(echo $output | cut -c$i)
case "$character" in
[[:space:]]) echo "key <space>" >> tim;;
*) echo "key $character" >> tim;;
esac
done

fi
done

now, this finds the lines with "key 0", but still is writing to the end of the file, instead of writing over the lines that it finds. so my logic is all messed up.

basically, there is a block of text in the file that i want to overwrite with this output
# 10  
Old 10-27-2008
Hope below perl script can throw some light on you!!!

Code:
%hash=(' ','space','	','tab');
$str='a b	cde';
for($i=0;$i<(length $str);$i++){
	$key=($hash{substr($str,$i,1)}eq "")?substr($str,$i,1):$hash{substr($str,$i,1)};
	print "key ",$key,"\n";
}

# 11  
Old 10-27-2008
Quote:
Originally Posted by summer_cherry
Hope below perl script can throw some light on you!!!

Code:
%hash=(' ','space','	','tab');
$str='a b	cde';
for($i=0;$i<(length $str);$i++){
	$key=($hash{substr($str,$i,1)}eq "")?substr($str,$i,1):$hash{substr($str,$i,1)};
	print "key ",$key,"\n";
}

thank you for the reply! i do not know perl very much, but i saved that in a .py file and ran it 'python file.py' and it gave me an error on line 1
# 12  
Old 10-28-2008
its a perl script, not a python script. so you just type perl script.pl
# 13  
Old 10-28-2008
Quote:
Originally Posted by twoodcc
take output of command 'uptime' (up 32 days, 23:09)
place in file 'myFile'

output:
...
key u
key p
key space
key 3
key 2
key space
key d
...

anyone have any idea on how to do this?

thanks in advance
Code:
uptime | awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++) print $i}'

# 14  
Old 10-28-2008
Quote:
Originally Posted by ghostdog74
its a perl script, not a python script. so you just type perl script.pl
oh, thanks! my mistake.

well, it ran, but what does it actually do?

Quote:
Originally Posted by ghostdog74
Code:
uptime | awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++) print $i}'

well, this works, but doesn't do exactly what i had in mind. the output just prints each character on a new line, but i need it to add "key " before each character.

and i need to overwrite a certain part of a file with this data.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assistance on complicated perl script

As a followup to my previous thread, I'm trying to make a complicated perl script that involves storing information from a text file into a hash, and giving the user the ability to change the information present/write the information currently inside the hash to a new file. This is the code I've... (8 Replies)
Discussion started by: Eric1
8 Replies

2. Shell Programming and Scripting

Help on a fairly complicated shell script

Hello, also with the help of some great users of this forum, I have created following shell script. MM=120 GG=5000 # get size of directory szm=$(du -s --block-size M ./192.168.1.xxx | awk '{print int($0)}') data=$(date --rfc-3339=seconds) if ; then # too big delete older files ... (10 Replies)
Discussion started by: dcaccount
10 Replies

3. Shell Programming and Scripting

Search complicated strings on file

Can someone help me? I been figuring out how I can search and extract a complicated search string from a file. The whole string is delimited by a period. And the file where I'm searching is composed of differnt string such as that. For example, I have this search string: and I have a file... (3 Replies)
Discussion started by: Orbix
3 Replies

4. Shell Programming and Scripting

Script Search replace - complicated

I have a text file for which i need a script which does some fancy search and replace. Basically i want to loop through each line, if i find an occurance of certain string format then i want to carry on search on replace another line, once i replaced this line i will contine to search for the... (7 Replies)
Discussion started by: kelseyh
7 Replies

5. Shell Programming and Scripting

Parsing a Complicated properties file

Hi All, I have a requirement to parse a file. Let me clear you all on the req. I have a job which contains multiple tasks and each task will have multiple attributes that will be in the below format. Each task will have some sequence number according to that sequence number tasks shld... (1 Reply)
Discussion started by: rajeshorpu
1 Replies

6. Shell Programming and Scripting

Complicated(?) text file comparison

I've got two files, both plain text. Each file is a datafeed of products, pipe delimited. The current file is in directory 1 and yesterday's file is in directory 2 (literally, those are the directory names). What I'm trying to do is compare the files and pull out products whose price has changed... (3 Replies)
Discussion started by: Daniel M. Clark
3 Replies

7. Shell Programming and Scripting

complicated search within file

Hi, I have following problem. I have a file with time stamps and some data describing what happened between time stamps. Something like this: 10:00 meeting with K meeting with L 11:00 lunch 12:00 work with K 13:00 From this file I have to get a file with... (7 Replies)
Discussion started by: mmike
7 Replies

8. Shell Programming and Scripting

Very complicated script..

I have a script that I need to create tha involves moving files and renaming them(see previous post) Are there any websites with user made shell scripts? (5 Replies)
Discussion started by: rocinante
5 Replies

9. Shell Programming and Scripting

Need help with complicated script (reading directories, extracting data)

Hi, people. I was searching script tutorials/examples and found this forum, and thought to ask for help, because there seems to be many wise people here. (Try to bare with me, I'm a Windows user, so this stuff is somewhat strange to me, OK? :rolleyes: ) Anyways, I need to create a script that... (3 Replies)
Discussion started by: Gill Bates
3 Replies

10. Shell Programming and Scripting

Complicated string searching in a file

Hi folks, Following a part of opmn.xml file: <process-type id="OC4J_RiGHTv_PLATOR81" module-id="OC4J"> <environment> <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/> <variable id="SHLIB_PATH"... (5 Replies)
Discussion started by: nir_s
5 Replies
Login or Register to Ask a Question