Put two lines into one from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Put two lines into one from file
# 1  
Old 07-10-2008
Put two lines into one from file

Hello, I have a script that generates the following file named /tmp/rfkill:

Code:
rf55 pts/13 Jul 10 06:38 (10.72.11.44) 
 15782 pts/13  5:07 b                  
rf56 pts/15 Jul 10 06:53 (10.72.11.9)  
 18552 pts/15  0:28 b                  
rf55 pts/39 Jul 10 09:12 (10.72.11.44) 
 19354 pts/39  0:04 b                  
rf56 pts/55 Jul 10 08:36 (10.72.11.9)  
 35368 pts/55  0:47 b                  
rf17 pts/56 Jul 10 08:36 (10.72.11.22) 
 22668 pts/56  0:00 b                  
rf17 pts/59 Jul 10 08:43 (10.72.11.22) 
 27718 pts/59  0:00 b

when I do
Code:
cat /tmp/rfkill | awk '{print$1,$3,$6}'

I get
Code:
rf55 Jul (10.72.11.44)
15782 5:07            
rf56 Jul (10.72.11.9) 
18552 0:28            
rf55 Jul (10.72.11.44)
19354 0:04            
rf56 Jul (10.72.11.9) 
35368 0:47            
rf17 Jul (10.72.11.22)
22668 0:00            
rf17 Jul (10.72.11.22)
27718 0:00

Is there a way to get the PID and idle time to display on the same line as the name, time, and IP? The idea is to be able to sort first by IP and then by idle time so I can kill the oldest duplicate sessions of particular users.
ThanksSmilie
# 2  
Old 07-10-2008
Code:
sed 'N;s/\n //' /tmp/rfkill

# 3  
Old 07-10-2008
Cool thanks. How would it be possible to sort that output by IP address but also by idle time? So it would show first grouped by IP, then within that sorted by idle time?
# 4  
Old 07-10-2008
Like this?

Code:
sed 'N;s/\n //' /tmp/rfkill|sort -k6,6 -k9,9n

# 5  
Old 07-10-2008
Yes, exactly. Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Put in one line only the lines with digits

Hello, I haven't been here for a while and I might be forgetting some things. I have an input text like this titleA http://myurl/bla/blabla/1234 http://myurl/bla/blabla/6789 titleB http://myurl/bla/blabla/5678 http://myurl/bla/blabla/1234 titleC http://myurl/bla/blabla/9123... (10 Replies)
Discussion started by: Kibou
10 Replies

2. Shell Programming and Scripting

Put the lines from file A to end of lines in file B

I really can't figure this one out. I have 2 files, one file is a list of hostnames and the other is a list of their corresponding IPs: fileA: example.com another.org thirdie.net fileB: 1.1.1.1 2.2.2.2 3.3.3.3 I want to create a fileC that looks like: example.com 1.1.1.1... (2 Replies)
Discussion started by: zstar
2 Replies

3. Shell Programming and Scripting

Please Help! Need to put the lines of a txt to one line

Hi all, I'm quite newbie in shell scripting but I found a problem what I cant solve. I have a .txt file which looks like this: /22/ /23/ /24/ and so on and I'd need to make it look like this: /22/|/23/|/24/|...and so on. these numbers are growing and has lines like this /2a/ as well.... (15 Replies)
Discussion started by: gergo235
15 Replies

4. Programming

extracting information from lines, put them into arrays

hi I need a little help writing this small perl script. I'm trying to extract the values from each line in a file and find the average for example cat school Highschool 100, 123, 135 Middleschool 41, 67, 54 Elementary 76, 315, 384 ./average.pl highschool: 119.3 middleschool: 54... (2 Replies)
Discussion started by: gengar
2 Replies

5. Shell Programming and Scripting

How to search for multiple lines and put them into one paragraph?

Dear all, I'm trying to manipulate a data file and putting a certain lines into one paragraph. What am I actually want to do is that search some lines in a data file. These lines begin with "1\1\GINC-" and end with "\\@" or the following two empty lines as shown in blue. A part of the text... (11 Replies)
Discussion started by: liuzhencc
11 Replies

6. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

7. Shell Programming and Scripting

Put lines of a file in an array with awk

Hello, Is there any way in awk to put every line of a file in an array and so we can like this print the line we want. For example, if we have this file aaa eee bbb fff ccc ggg ddd hhh So we can print to the output the 3rd line only ccc ggg If it is possible, please put the... (7 Replies)
Discussion started by: rany1
7 Replies

8. UNIX for Dummies Questions & Answers

need to extract few lines from a file and put it in another file

Hi all, I have a file which contains comments,dotted lines(-------),actual records etc.I need to fetch only the actual records and put into a new file neglecting/deleting other rows.I have a header record too which contains the column names for the actual records.i need to discard this too.how... (5 Replies)
Discussion started by: ganesh_248
5 Replies

9. Shell Programming and Scripting

put the contents of this file into a variable with multiple lines

I have a file that contains the following lines the brown quick fox jumped over the white laze dog 0123456789 I wanted to put the contents of this file into a variable so I used this code: VAR_LIST=`cat $2` where $2 is the file name passed as an argument to the script If I... (3 Replies)
Discussion started by: Nomaad
3 Replies

10. UNIX for Dummies Questions & Answers

How to put the comments to 50 lines, using vi editor?

Hi All, Please let me know how I can put a comment (e.g // or #) to more than 50 lines using vi editor in a .cpp/.sh file. Thanks in advance. (3 Replies)
Discussion started by: artikulkarni
3 Replies
Login or Register to Ask a Question