How to Sort a file for given situation?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Sort a file for given situation?
# 1  
Old 11-25-2007
How to Sort a file for given situation?


How can you sort a file that is doubled space ( where even number lines are blank lines) and still preserves the blank lines?
You can use grep,sed and regular expression.

# 2  
Old 11-25-2007 can't. All you can do is sort the file and then put the doublespacing back.

sort | sed '/^$/d;G'

# 3  
Old 11-25-2007
can you please explain how it works?

Can You please explain with example like what type of content in and how it work?

# 4  
Old 11-25-2007
Hmmm, I think you'll learn it better if you just try it out yourself. But:

/^$/ matches blank lines (beginning of line followed by end of line)

d; deletes the line(s) that matched the pattern; starts a new command

G adds a newline

Good luck with the rest of your homework.
# 5  
Old 11-26-2007
I don't understand the question Smilie

Are you able to use 'sort' ?
Please give me an example.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Have a situation while extracting info

i have a text file which i am generating from few sqls. format is like : col1 col2 col3 col4 col5 1001 DONE ABC 17-sep-14 12:02:05 1001 DONE ABC 17-sep-14 12:02:05 1001 DONE ABC 17-sep-14 12:02:55 1001 REDONE ABC ... (6 Replies)
Discussion started by: deepakiniimt
6 Replies

2. Shell Programming and Scripting

Cat files situation

Hello, I am PhD student (Biomedical sciences) and very new to Linux. I need some help with the following task : I have files in the following format for their names : An_A1_nnn_R1.txt; An_A1_nnm_R1.txt; An_A1_nnoo_R1.txt An_A2_nnn_R1.txt; An_A2_nnm_R1.txt; An_A2_nno_R1.txt ... (8 Replies)
Discussion started by: Julio Finalet
8 Replies

3. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

4. HP-UX

Tricky situation getting IP address

Hi, I have a multihomed system HP-UX with two NIC cards having IP address & I have two weblogic servers running one listening on "" and the other on "" Given a PID how is it possible to extract the IP Address that the weblogic server is using and... (1 Reply)
Discussion started by: mohtashims
1 Replies

5. Shell Programming and Scripting

Strange situation of file sorting and merging

I have a strange situation of sorting and merging two files based on similar columns previusly both files has same count of records so, I made below way which is working fine until they reduced the count of one files . I.e. some times the count of records of both will same and some times it... (16 Replies)
Discussion started by: manas_ranjan
16 Replies

6. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

7. UNIX for Dummies Questions & Answers

help : crisis situation !!

Hi I had deleted important files from my company server :( the server is HPUX and i don't know how to undo rm command or how to restore the files .. iam appreciate for any help Thanx ... (5 Replies)
Discussion started by: Eisa
5 Replies

8. Programming

strange situation in file

Hi All, I am writing some data's into a file from C++ program. The files which i am writing is of fixed length . say 232 in length per line. I am writing as . my c code is as ... (0 Replies)
Discussion started by: arunkumar_mca
0 Replies

9. Shell Programming and Scripting

sed situation

Hi, I'm looking for someone who can think in sed. Basically, I need the trailing characters on every line in a file to be deleted. These characters are all in capitals, and always follow a number, but they often vary in number For instance, on the line: 2006_10_9_p20_TALK I'd want to... (4 Replies)
Discussion started by: Laurel Maury
4 Replies

10. UNIX for Advanced & Expert Users

current situation

hello..what is the current situation or lastest version of UNIX?? Is there any where i can read more about it?? (2 Replies)
Discussion started by: joanne6298
2 Replies
Login or Register to Ask a Question