![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Displaying specific lines in a file. | MaestroRage | UNIX for Dummies Questions & Answers | 3 | 02-05-2008 12:57 PM |
| How do you specific lines in a file? | hedgehog001 | UNIX for Dummies Questions & Answers | 2 | 08-22-2005 09:04 PM |
| Cutting specific name from configuration file | nir_s | Shell Programming and Scripting | 8 | 03-01-2005 07:38 AM |
| Cutting n consecutive lines from a file... | Vishnu | UNIX for Dummies Questions & Answers | 2 | 10-18-2002 07:49 AM |
| extract specific lines from file | apalex | UNIX for Dummies Questions & Answers | 2 | 05-15-2001 06:57 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi,
I have a file named Mani.txt. The contents are like this cat Mani.txt -------------------------------------------------------- Hi there how r u My Name is Mani Bye ------------------------------------------------------------ I want to cut the first and last lines from the file Mani.txt. I want the output file to contain only the line 'My Name is Mani'. Please help me out. If , possible give me a snippet of the code Thanx in advance |
| Forum Sponsor | ||
|
|
|
|||
|
Hi,
Thanx. What should I do if want the first and last line of Mani.txt I have a file called Log.txt. The contents of the file are -------------------------------------------------------------------------- Creating Control File for sqlloader Control file (data.ctl) Created for sqlloader The execution of tool has started at Tue, May 31, 2005 03:45:37 AM The User running the tool is DACSCAN The present working directory is /usr/dacscan/toolbin Temporary Table Created for Updating the Original Table Temp Table have been created for storing the updated Records Updation Successfully Completed on the Original Table SQL> select * from spr1; DOMAIN_NAME CKT COLOR SYS_UPDATE -------------------- ------------------------------ ----- ---------- AREA_hickory 76L/37_690021/7JK1-711020/7JK1 R Y AREA_hickory 76L/37_690021/7JK1-711020/7JK2 G N AREA_aspen 76L/37_690021/7JK1-711020/7JK1 R Y SQL> spool off; Temp Table for storing updated records have been dropped Temp Table created for updating the original Table is Dropped All the Original Files have been moved to /dacscan/trace Folder The execution of tool has finished execution at Tue, May 31, 2005 03:45:48 AM The tools execution time is from Tue, May 31, 2005 03:45:37 AM to Tue, May 31, 2005 03:45:48 AM ------------------------------------------------------------------------ I want to remove the sentences SQL>select * from spr1 and SQL> spool off; What should I do Thanx in advance |
|
|||
|
You told us you want everything except for the last and the first line, but presented us a 5-line file in your first post. Does this mean you want to skip all empty lines?
Supposing you want empty lines to go into your result (this would yield not only the line "my name is mani" in you first example, but also the two empty lines surrounding it) you could use: # cat <file> | sed -n '1d; $d; p' This will ignore the last and first line and print out everything else. In case you want to skip empty lines (lines containing only whitespace) too: # cat <file> | sed -n '1d; $d; /^[<blank><tab>]*$/d; p' To display the first/last line is trivial and could be done by sed too, but you have gotten a working solution already. To display the first nonblank line use: # cat <file> | sed -n '/^[<blank><tab>]*$/d; /^..*$/ {; p; q;}' You should be able to work out the solution for the last nonblank line now for yourself. "<blank>" and "<tab>" in the text above is to be replaced by literal blanks and tabs of course. bakunin |
|||
| Google UNIX.COM |