incrementing lines in the file & format output.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting incrementing lines in the file & format output.
# 1  
Old 08-29-2011
incrementing lines in the file & format output.

Hi All,
I need read the file and out put format as below using ksh, I wrote below script its keep on repeating first line in the file.
may i know the best way to get the below out put while incrementing line in the file.
Code:
cat b.txt |awk '{print $0}' |while read line
do
aa=`cat $line |head -1 |sort -n`
bb=`cat b.txt |head -2 |sort -n |head -1`
echo $aa $bb
done

in my file
Code:
rs6qditim06_A_DMX3_7bB
c0:50:76:03:06:0e:00:08
rs6qditim07_B_DMX3_7bB
c0:50:76:03:06:0e:00:0a

output need to format
Code:
rs6qditim06_A_DMX3_7bB  c0:50:76:03:06:0e:00:08
rs6qditim07_B_DMX3_7bB  c0:50:76:03:06:0e:00:0a

May thanks in advance.

Thx!
Ashan

Last edited by radoulov; 08-31-2011 at 06:02 PM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 08-29-2011
Is this what you want:
Code:
paste -d' ' - - < Inp_File

# 3  
Old 08-29-2011
How do i increment each line in the file and read, If can assign to two variables while increment line then i can get the output I need.

cat b.txt |paste -s -d " " - > c.txt
output

rs6qditim06_A_DMX3_7bB c0:50:76:03:06:0e:00:08 fra1bvch03p_B_DMX3_8bB c0:50:76:03:06:0e:00:0a

I need the out like below
rs6qditim06_A_DMX3_7bB c0:50:76:03:06:0e:00:08
fra1bvch03p_B_DMX3_8bB c0:50:76:03:06:0e:00:0a





# 4  
Old 08-29-2011
I really didn't understand your script but if you just want to change every 1, 3, 5, etc. newlines to spaces, then pipe it to
Code:
sed  'N; s/\n/ /'

# 5  
Old 08-29-2011
Txh! it works for me. now i can fix my script.

Code:
cat b.txt |sed 'N; s/\n/ /'
rs6qditim06_A_DMX3_7bB c0:50:76:03:06:0e:00:08
fra1bvch03p_B_DMX3_8bB c0:50:76:03:06:0e:00:0a


Last edited by radoulov; 08-31-2011 at 06:02 PM.. Reason: Please use code tags for code and data samples, thank you
# 6  
Old 08-29-2011
Quote:
Originally Posted by ashanabey
How do i increment each line in the file and read, If can assign to two variables while increment line then i can get the output I need.
cat b.txt |paste -s -d " " - > c.txt
output
Sir, make sure you use EXACTLY the proposed solution:
Code:
paste -d' ' - - < Inp_File

I never suggested you use:
Code:
cat b.txt |paste -s -d " "  - > c.txt

The solution:
Code:
sed  'N; s/\n/ /'

does not output the last line for an odd number of lines file. Example:
Code:
Line1
Line2
Line3

The output will be:
Code:
Line1 Line2

The last record "Line3" will not be displayed.

If you want to use "sed", here is a working solution:
Code:
sed '$!N;s/\n/ /'

# 7  
Old 08-31-2011
how do i incrementing lines in any txt file and print.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing specific and incrementing lines of text from file via variable

This is part of a larger script where I need to pass only 1 line of a file to the script, based on a variable and not a direct reference. As part of a for loop : # for((line=0;line<50;line++)); do # awk ‘NR==$line' PhraseList.txt; done ... (5 Replies)
Discussion started by: Seth
5 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

How to format output in columns by appending multi lines one by one?

Hi, I need to display output in below format Customer : Apr 24 16:31 Customer_Name_111121.txt |---Space---|Apr 24 16:32 Customer_Name _111121. txt |---Space---|Apr 24 16:34 Customer_Name_111112. txt |---Space---|Apr 24 16:35 Customer_Name _222223. txt |---Space---|Apr 24 16:37... (8 Replies)
Discussion started by: ketanraut
8 Replies

4. Shell Programming and Scripting

Output pipes and incrementing

Hi... Basically, mycode does following: it loops through every file in directory and gets second lines of those files (second lines contains IPs). Then it creates a new file with IP which is greater than other IPs. I have two problems: 1) when I echo for checking A B C D there are... (2 Replies)
Discussion started by: Manu1234567
2 Replies

5. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

6. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

7. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

8. Shell Programming and Scripting

manipulate & format the output of spool command

Hi All, I am spooling the data some sql queries into a single file but wanted to know how to format the data of the file generated by spool. #!/bin/sh unset -f USAGE USAGE () { clear echo "############################USAGE#######################\n" echo "Incorrect number of... (2 Replies)
Discussion started by: ss_ss
2 Replies

9. Shell Programming and Scripting

Cronjob - Redirect mail output to file, LINES & COLUMNS

I currently have an expect script that issues the 'mail' command and sends an 'x' when it receives the & prompt from mail to quit. The expect script is able to do stty rows 100 columns 200 < $spawn_out(slave,name) to set up the number of columns and rows. I would like to get rid of the expect... (0 Replies)
Discussion started by: jharvey
0 Replies

10. Solaris

Making sense of df -k & format verify output

I'm posting the output from two disks on my Solaris machine. The first part is the output from using the format command and then using the verify option on each disk. The last part is the output from my df -k command. I'm trying to match the partition to the filesystem/mount point. I'm assuming... (13 Replies)
Discussion started by: gonzotonka
13 Replies
Login or Register to Ask a Question