01-28-2009
sed in while loop producing arithmetic output
Hi all
Just wondering if someone can help me with this. I'm trying to write a script that processes the output of another file and prints only the lines I want from it.
This is only the second script I have written so please bare with me here. I have referred to the literature and some of the previous posts and I'm sure I have the logic and syntax correct. It computes, but it takes ages and gives me the wrong output.
heres the code:
#Set the line number variables
filelinenumber=1
datalinenumber=8
lines=`sed -n '$=' test1.out`
while [ $datalinenumber -le $lines ]
do
# print the selected lines into the new file mpck2.out
sed -n "${filelinenumber}p" test1.out` > mpck2.out
sed -n "${datalinenumber}p" test1.out > mpck2.out
# increment the line number variables
filelinenumber=`expr $filelinenumber + 11`
datalinenumber=`expr $datalinenumber + 11`
done
Instead of a file full of the program lines I want I'm just getting this
$ cat mpck2.out
average 156956
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a forloop which checks a log for a set of 6 static IP addresses and each IP found is logged to a file which is then mailed to me.
After the forloop I always have a text file that may contain up to 6 IP addresses or may contain 0.
What I want to do is substitute the IP addresses (if any)... (2 Replies)
Discussion started by: Moxy
2 Replies
2. Shell Programming and Scripting
I have file with this type of format
01.02.09 08:30
bob
jill
mark
01.04.09 07:00
bob
jill
mark
tom
I want to count the names after the date /ime line (01.02.09 08:30) and add that number after the time like this
01.02.09 08:30 3
01.04.09 07:00 4
I don't care about... (6 Replies)
Discussion started by: marcelino
6 Replies
3. Shell Programming and Scripting
Hi all,
Could someone please advise what is the correct syntax for my little script to process a table of values?
The table is as follows:
0.002432 20.827656
0.006432 23.120364
0.010432 25.914184
0.014432 20.442655
0.018432 20.015243
0.022432 21.579517
0.026432 18.886874... (9 Replies)
Discussion started by: euval
9 Replies
4. Shell Programming and Scripting
Hello everyone,
I need some assistance with what I thought would have been a very simple script.
Purpose of Script:
Script will parse through a source file and modify (search/replace) certain patterns and output to stdout or a file. Script will utilize a "control file" which will contain... (12 Replies)
Discussion started by: packetjockey
12 Replies
5. Shell Programming and Scripting
Hi
I have a file with 3 columns. say,
infile:
1 50 68
34 3 23
23 4 56
-------
-------
I want to generate n files from this file using a loop so that 1st column in output file is (column1 of infile/(2*n+2.561))
I am doing like this:
for ((i=1; i<=3; i++))
do
a=`echo... (3 Replies)
Discussion started by: Surabhi_so_mh
3 Replies
6. Shell Programming and Scripting
Hi
I want to perform arithmetic operations on output of `wc -l`.
for example
user046@sshell ~ $ ls -l
total 0
where "total 0" will increase one line in wc -l
filecount=`ls -l | wc -l`
here $filecount will be 1 but is should be 0
how to get rid of it ? (1 Reply)
Discussion started by: anandgodse
1 Replies
7. Shell Programming and Scripting
Hey guys, awk is putting out too many results, two of each specifically. See below.
Code:
read CPU_VENDOR_ID <<< $(cat /proc/cpuinfo | grep "vendor_id" | awk -F: '{print $2}')
echo $CPU_VENDOR_ID
echo
Output:
AuthenticAMD AuthenticAMD
I only want it to print out "AuthenticAMD" once.
... (7 Replies)
Discussion started by: 3therk1ll
7 Replies
8. Shell Programming and Scripting
My original post did not show up properly. I am trying again.
I have a simple tsch script that does some basic arithmetic. The calculated value was not producing the result I was expecting. I wrote a sample script to illustrate the things that I tried.
#!/bin/tcsh
@ count = 43
@... (3 Replies)
Discussion started by: sgualandri
3 Replies
9. Shell Programming and Scripting
Hi,
I have a text file with some thousands of rows of the following kind (this will be referred to as the inputFileWithColorsAndNumbers.txt):
Blue 6
Red 4
Blue 3
Yellow 4
Red 7
Colors in the left column and a number in the right one for each line. I want to run an awk... (5 Replies)
Discussion started by: Zooma
5 Replies
10. Shell Programming and Scripting
So I am writing a bash script that will search a file line by line for unix timestamps, store all of the timestamps into an array, then check how many of those timestamps were created within the last hour, and finally increment a counter every time it finds a timestamp created within the last hour.... (6 Replies)
Discussion started by: jsikarin
6 Replies
head(1) General Commands Manual head(1)
NAME
head - Displays the beginning of files
SYNOPSIS
Current Syntax
head [-c bytes] [-n lines] [file...]
Obsolescent Syntax
head [-lines] [file...]
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
head: XCU5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
OPTIONS
The default count is 10. [Tru64 UNIX] Specifies the number of bytes to display. If the last byte written is not a newline character, a
newline character is appended to the output. Specifies the number of lines to display Works exactly as -n lines. Obsolescent.
OPERANDS
Path name of the input file. If you do not specify a file, head reads standard input.
DESCRIPTION
The head command copies the standard input to standard output, ending output of each file at the specified point.
NOTES
The obsolescent form is subject to withdrawal at any time.
EXIT STATUS
The following exit values are returned: Successful completion. An error occurred.
EXAMPLES
To display the first 5 lines of a file called test, enter: head -n 5 test To display the first ten lines of all files (except those with a
name beginning with a period), enter: head *
ENVIRONMENT VARIABLES
The following environment variables affect the execution of head: Provides a default value for the internationalization variables that are
unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari-
ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value,
overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as opposed to multibyte characters in arguments and input files). Determines the
locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the
processing of LC_MESSAGES.
SEE ALSO
Commands: cat(1), more(1), pg(1), sed(1), tail(1)
Standards: standards(5)
head(1)