From multiple line to one line to multiple line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting From multiple line to one line to multiple line
# 8  
Old 09-03-2008
Or this:

Code:
awk '{for(i=1;i<=NF;i++){printf("%s ", $i);if(i%3==0){print ""}}}' $FILENAME >> $REPORT

Regards

Last edited by Franklin52; 09-03-2008 at 03:31 PM.. Reason: adapt code
# 9  
Old 09-03-2008
Quote:
Originally Posted by tipi
Ok, this do exactly what I want

sed -n 's/[0-9\.\-].* [0-9\.\-].* [0-9\.\-].*/&/w $REPORT' <$FILENAME

Thanks for help,

Tipi
glad you done it by yourself

cheeeeeeerrrrrrrrsssssss........Smilie
# 10  
Old 09-03-2008
Quote:
Originally Posted by dennis.jacob
I am not getting the kind of output which you got as you mentioned with your code..

Anyway try this:

Code:
awk '/[0-9\.\-].* [0-9\.\-].* [0-9\.\-].*/ { print $0 "\n"; }' filename

This work fine too, thanks!
# 11  
Old 09-03-2008
Hi, tipi.

You code works for me:
Code:
#!/bin/bash -

# @(#) s1       Demonstrate extraction of coordinates.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) grep
set -o nounset
echo

FILE=${1-data1}
rm output
cat >output <<'EOF'
This is some data that already appears on file output.
We will be appending to this.

EOF

echo " Data file $FILE:"
cat $FILE

grep "[0-9\.\-].* [0-9\.\-].* [0-9\.\-].*" $FILE >>output

echo
echo " Output file:"
cat output

exit 0

Producing:
Code:
% ./s1

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
grep (GNU grep) 2.5.1

 Data file data1:
This is a data file.
0.1 0.1 0.1
2 2 2
0.03 0.03 0.03
...
We want to extract the lines with coordinates.
4 5 6
0.4 0.5 0.6
40. 50. 60.
End of the data.

 Output file:
This is some data that already appears on file output.
We will be appending to this.

0.1 0.1 0.1
2 2 2
0.03 0.03 0.03
4 5 6
0.4 0.5 0.6
40. 50. 60.

cheers, drl
# 12  
Old 09-03-2008
Quote:
Originally Posted by drl
Hi, tipi.

You code works for me:
[...]
cheers, drl
Damn, in fact, the code I used was

echo `grep "[0-9\.\-].* [0-9\.\-].* [0-9\.\-].*" $FILENAME` >> $REPORT

So the echo was my problem???

EDIT : this is not a real question... I understand!
# 13  
Old 09-03-2008
Hi, tipi.
Quote:
Originally Posted by tipi
Damn, in fact, the code I used was

echo `grep "[0-9\.\-].* [0-9\.\-].* [0-9\.\-].*" $FILENAME` >> $REPORT

So the echo was my problem???

EDIT : this is not a real question... I understand!
I'm glad you understand.

This is a good lesson: it is important to tell us exactly what you did so that responders can diagnose the problem. Your initial code did not include the echo.

I think most of the people who responded could have quickly told you the solution ... cheers, drl
# 14  
Old 09-03-2008
I dont understand why I cut and paste only that part of the command. Maybe I was convinced that the problem was in that part.

Sorry to have made you waste time...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

2. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies

3. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

4. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

5. Shell Programming and Scripting

Merge multiple lines to one line when line starts with and ends with

example: comment Now_TB.table column errac is for error messages 1 - first 2 - second 3 -third ; in this example I need to be able to grab the comment as first word and ; as the last word and it might span a few lines. I need it to be put all in one line without line breaks so I can... (4 Replies)
Discussion started by: wambli
4 Replies

6. Shell Programming and Scripting

convert single line output to multiple line

Hi all, I have a single line output like below echo $ips 10.26.208.28 10.26.208.26 10.26.208.27 want to convert above single line output as below format. Pls advice how to do ? 10.26.208.28 10.26.208.26 10.26.208.27 Regards Kannan (6 Replies)
Discussion started by: kamauv234
6 Replies

7. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

8. Shell Programming and Scripting

KSH: Reading a file line by line into multiple arrays

Hi - I have a file that contains data in this format:- #comment value1 value2 value3 #comment value4 value5 value6 value7 #comment value8 value9 I need to read value1, value2 and value3 into one array, value4 value5 value6 and value7 into another array and value8 and value9 into a 3rd... (2 Replies)
Discussion started by: sniper57
2 Replies

9. Shell Programming and Scripting

Compare multiple fields in file1 to file2 and print line and next line

Hello, I have two files that I need to compare and print out the line from file2 that has the first 6 fields matching the first 6 fields in file1. Complicating this are the following restrictions 1. file1 is only a few thousand lines at most and file2 is greater than 2 million 2. I need to... (7 Replies)
Discussion started by: gillesc_mac
7 Replies

10. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies
Login or Register to Ask a Question