how to print off results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to print off results
# 8  
Old 01-24-2012
Can't explain why tail if failing to open the file.

You could try:
Code:
tail -2 < /var/tmp/$ip/test.log | head -1

or
Code:
cat  /var/tmp/$ip/test.log | tail -2 | head -1

This User Gave Thanks to Chubler_XL For This Post:
# 9  
Old 01-24-2012
Quote:
Originally Posted by Chubler_XL
Can't explain why tail if failing to open the file.

You could try:
Code:
tail -2 < /var/tmp/$ip/test.log | head -1

or
Code:
cat  /var/tmp/$ip/test.log | tail -2 | head -1



no it was me being stupid, see my updated question on this...also

from the output I need not print off the path i.e output is

Code:
/var/tmp/1.1.1.1/test.log: HELLO 1.1.1.1: +6485s: output  failed

just need

Code:
HELLO 1.1.1.1: +6485s: output  failed

---------- Post updated at 03:25 AM ---------- Previous update was at 03:07 AM ----------

figured it, removed first printf statement


Code:
while read ip
do
  tail -2 /var/tmp/$ip/test.log | head -1
done < /tmp/ip_list


can you advise on my question on page 1 of this thread please
# 10  
Old 01-25-2012
Quote:
Originally Posted by slashbash
one thing I don't understand is $ip variable is used after printf statement then in tail statement after /var/tmp/$ip don't understand this bit
In a earlier post you said that things were printing all over the place. The printf was just so you could see what file each line was comming from.

printf outputs the pathname of the file with ip address slotted in at the %s position eg /var/tmp/1.1.1.1/test.log:, as no CR is on the end of this line the output of head+tail appends on the end.
This User Gave Thanks to Chubler_XL For This Post:
# 11  
Old 01-25-2012
Quote:
Originally Posted by Chubler_XL
In a earlier post you said that things were printing all over the place. The printf was just so you could see what file each line was comming from.

printf outputs the pathname of the file with ip address slotted in at the %s position eg /var/tmp/1.1.1.1/test.log:, as no CR is on the end of this line the output of head+tail appends on the end.

ok thanks.

few q's

how does %s & $ip know that ip_list entry should be output here? what's the correlation sorry if that sounds dumb.

also

tail -2 is second to last line
with | head -1 are we saying pipe the second to last line with 1 line only ?
# 12  
Old 01-25-2012
The "while read ip" statment populates the ip environment variable from the file 1 line at a time. and then executes all code to the done statement.

printf has the format of:
Code:
printf format_string arg1 arg2 arg3 ...

Here is a couple of examples - (check man printf for more):
Code:
printf "%10s%6.2f\n" test 12
      test 12.00
printf "Name: %s Age:%d\n" "John Jones" 25
Name: John Jones Age:25

So:
%10s formats first argument (test) as a 10 wide right justified string (Use %-10 for left justified)
%6.2f formats 2nd argument (12) as 6 (full stop and 2 digits count in width too) wide float with 2 decimal places
%s first argument (John Jones) as a variable width string
%d 2nd argument (25) as variable width integer.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for names in one list in another and print results

Hi All , New to the Bash / Shell programming world and looking for some help I have two files 1: Contains a list of names : eg STEVE BOB CRAIG 2: Contains information with those included names but also others that are not in the list (1 Reply)
Discussion started by: Lonerg550
1 Replies

2. Shell Programming and Scripting

Parsing OSX UNIX command results which print in multiple lines

from the CLI on a Mac, if you type networksetup -listallnetworkservices then you get results in a multi-line paragraph that look something like this: networksetup -listallnetworkservices An asterisk (*) denotes that a network service is disabled. Wi-Fi Display Ethernet Bluetooth DUN... (7 Replies)
Discussion started by: hungryd
7 Replies

3. UNIX for Dummies Questions & Answers

How to print results from two lines using awk?

I need to print a specific string from an html file that's always occurring between two other known strings. Example: from the text below, I would like to print the bolded part: <this is a lot of text before the string I want to print> fullpath: abc/def/ghi/example.xlf -cfver. <sample text... (15 Replies)
Discussion started by: danegon
15 Replies

4. Shell Programming and Scripting

Awk find in columns with "if then" statement and print results

I have a file1.txt file1.txt F-120009210","Felix","U-M-F-F-F-","white","yes","no","U-M-F-F-F-","Bristol","RI","true" F-120009213","Fluffy","U-F-","white","yes","no","M-F-","Warwick","RI","true" U-120009217","Lity","U-M-","grey","yes","yes","","Fall River","MA","true"... (4 Replies)
Discussion started by: charles33
4 Replies

5. Shell Programming and Scripting

How to print sed results

Dear all, How can I print results (and of course, send this result to the text file) of sed command. I mean, I want to know which lines of which files sed command has found. For e.g, the result text file should contains: file1.c:line 12 file2.h:line 14 file2.h:line 37 Please help me (10 Replies)
Discussion started by: Hannibal2010
10 Replies

6. Shell Programming and Scripting

Print some results in a text file using script in linux

hello everyone, i really need your help to write a script which would just print following kind of result into a text file (result.txt) XYZ test Results ID: <unique-id> Date: <date> ------------------------------------------------- | Task | Result | Time |... (3 Replies)
Discussion started by: viriimind
3 Replies

7. Shell Programming and Scripting

Script template for inputting filenames and print results

Hi, Hope you are all well. New to scripting, and all those characters are all a new language for me. Though hoping to get my little head round it all sooner or later. I was wondering whether anyone could help with a script template example. What I would like to happen is to run the script... (8 Replies)
Discussion started by: loky27
8 Replies

8. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

9. Shell Programming and Scripting

Print just 1 results from the whole line

Hi All, need some help with writing a shell script. I tried to search this forum but couldn't find exactly what i want. If you all know any reference link i can read and refer to solve my issue, let me know. I got 1 file i.e: example.txt. It is content list of data, as below example. What... (2 Replies)
Discussion started by: anakiar
2 Replies

10. Shell Programming and Scripting

search file and print results with shell script

input file 1.<CRMSUB:MSIN=0100004735,BSNBC=TELEPHON-9814060328-TS11&TS21&TS22,NDC=9814,MSCAT=ORDINSUB,SUBRES=ALLPLMN-SPICE,BAOC=OIC,BAPRC=INFO,ACCSUB=BSS,NUMTYP=MULTI;... (3 Replies)
Discussion started by: dodasajan
3 Replies
Login or Register to Ask a Question