Computing.Net > Forums > Unix > awk and shell programming,need help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk and shell programming,need help

Reply to Message Icon

Name: john
Date: April 29, 2003 at 09:32:15 Pacific
OS: IRIX6.5
CPU/Ram: R10000/256MB
Comment:

Hi, everyone,

I am writting a script to make many data files from a single input. The idea is, take a 50 line input as an example, that the script will take line1-15 as file1, line2-16 as file2, line3-17 as file3, and so on until line36-50 as file36.

I assembled two scripts as following, but there is always error message. Because I am not really good on this, just post here to see if anyone can help me.

It seems that some lines I am trying to post will be missed.

Thanks in advance.

1st:

#!/bin/sh

nr=`wc $1 | nawk '{print $1}'`
for (j=1; j file
close(file)
}
}' $1
done
-----------------
2nd:

#!/bin/sh

nr=`wc $1 | nawk '{print $1}'`

for (j=1; j file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
getline
print $0 > file
close(file)
}
}
}' $1



Sponsored Link
Ads by Google

Response Number 1
Name: LANkrypt0
Date: April 29, 2003 at 11:33:12 Pacific
Reply:

Done in KSH, but it worked fine for me.
The $startnumber and $readwidth variable basically control the whole thing, you can play with them to get different results, but ideally they should be the same as the startnumber is for the head command (it will read the first $startnumber lines) and the readwidth will tail the last $readwidth lines of that initial head. So if you have $startnumber as 17 the $readwidth will then read lines 3-17. Anyway im sure you get the idea. Try it, see if it works.

#!/bin/ksh
linesinfile=`wc -l testfile|awk '{print $1}'`
startnumber=15
readwidth=15
filenumber=1

until [[ $startnumber -eq $(($linesinfile+1)) ]];do
head -$startnumber testfile | tail -$readwidth > file$filenumber
startnumber=$(($startnumber+1))
filenumber=$(($filenumber+1))
done


0

Response Number 2
Name: john
Date: April 29, 2003 at 11:53:23 Pacific
Reply:

Dear LANkrypt0,

It works great. Thank you so much.


0

Response Number 3
Name: LANkrypt0
Date: April 29, 2003 at 12:19:58 Pacific
Reply:

aint no thing but a chicken wing.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: awk and shell programming,need help

About Shell script - Need help www.computing.net/answers/unix/about-shell-script-need-help-/5796.html

Unix Shell program www.computing.net/answers/unix/unix-shell-program/3441.html

shell programming need help!!!!! www.computing.net/answers/unix/shell-programming-need-help/4924.html