delete blank line from middle of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete blank line from middle of a file
# 1  
Old 08-31-2011
delete blank line from middle of a file

All,

I have a file which contains two entry with spaces (either one or more than one space). ex.
Code:
/tmp/scripts/sql        CUST_YR_END_INI.sql
/tmp/scripts/sql        CUST_WK_END_INI.sql
/tmp/scripts/sql        CUST_MTH_END_INI.sql
/tmp/scripts/sql        CUST_YR_END_INC.sql

now I want to replac spaces with /

I need my output as.
Code:
/tmp/scripts/sql/CUST_YR_END_INI.sql
/tmp/scripts/sql/CUST_WK_END_INI.sql
/tmp/scripts/sql/CUST_MTH_END_INI.sql
/tmp/scripts/sql/CUST_YR_END_INC.sql

Could any one please help me how I can do this through script.

Thanks,
Anshu

Last edited by Franklin52; 08-31-2011 at 05:23 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 08-31-2011
Code:
sed 's/ \+/\//g' <filenames


Last edited by Skrynesaver; 08-31-2011 at 06:30 AM.. Reason: Misread the original question
# 3  
Old 08-31-2011
Quote:
Originally Posted by anshu ranjan
All,

I have a file which contains two entry with spaces (either one or more than one space). ex.
Code:
/tmp/scripts/sql        CUST_YR_END_INI.sql
/tmp/scripts/sql        CUST_WK_END_INI.sql
/tmp/scripts/sql        CUST_MTH_END_INI.sql
/tmp/scripts/sql        CUST_YR_END_INC.sql

now I want to replac spaces with /

I need my output as.
Code:
/tmp/scripts/sql/CUST_YR_END_INI.sql
/tmp/scripts/sql/CUST_WK_END_INI.sql
/tmp/scripts/sql/CUST_MTH_END_INI.sql
/tmp/scripts/sql/CUST_YR_END_INC.sql

Could any one please help me how I can do this through script.

Thanks,
Anshu
Try:
Code:
sed 's/ /\//';'s/ //g' file

# 4  
Old 08-31-2011
Code:
awk '$1=$1' OFS="/" file

Guru.
# 5  
Old 09-01-2011
Code:
$ awk '{print $1"/"$2}' inputfile

# 6  
Old 09-01-2011
Please share the significance of + here....

Quote:
Originally Posted by Skrynesaver
Code:
sed 's/ \+/\//g' <filenames


I am beginer in UNIX, would be glad if you can please share the significance of + in command: sed 's/ \+/\//g'
# 7  
Old 09-01-2011
+ --> Repeats the previous item once or more. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is matched only once

Regular Expressions Reference - Basic Syntax
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to delete blank line/s before and after a search pattern?

Hi, Test file x.txt below. This file is generated by a program that I unfortunately do not have control on how it gets presented/generated. create PACKAGE "XXX_INTERFACE_DEFECT_RPT_TEST" is TYPE refCursor IS REF CURSOR; Function queryRecords ( p_status varchar2, ... ... ... )... (4 Replies)
Discussion started by: newbie_01
4 Replies

2. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

3. Shell Programming and Scripting

Delete blank line in regular file

Hi all, I have file1 with line blank e.g. $cat file1 aaa 111 222 333 444 bbb 555 666 777 888 ccc ddd 1010 1010 1010 eee then i need delete the lines blank (3 and 5) so show $cat file1 aaa 111 222 333 444 bbb 555 666 777 888 ddd 1010 1010 1010 (5 Replies)
Discussion started by: aav1307
5 Replies

4. Shell Programming and Scripting

Delete the last empty/blank line of the text file

Hi All, I have a file.txt which seems like having three lines. wc -l file.txt 3 file.txt In fact, once it is open in text editor, this file has four lines where the last line is empty. how can i delete this last empty line of the file.txt? I tried the codes below so far but they... (6 Replies)
Discussion started by: senayasma
6 Replies

5. Shell Programming and Scripting

Need sed help: find regex and if the next next line is blank, delete both

I've got a report I need to make easier to read Using sh on HP-UX 11.12. In short, I want to search for a regular expression and when found, examine the next line to see if it's blank. If so, then delete both lines. If not blank, move on to the next regexp. Repeat. So far I've got: ... (7 Replies)
Discussion started by: Scottie1954
7 Replies

6. Shell Programming and Scripting

Delete last blank line.

I need to delete the last line only if its blank not otherwise. (3 Replies)
Discussion started by: dinjo_jo
3 Replies

7. Shell Programming and Scripting

sed: delete regex line and next line if blank

Hi, I want to write a sed script which from batiato: batiato/giubbe: pip_b.2.txt pip_b.3.txt pip_b.3mmm.txt bennato: bennato/peterpan: 123.txt consoli: pip_a.12.txt daniele: (2 Replies)
Discussion started by: one71
2 Replies

8. Shell Programming and Scripting

how to delete a first blank line from the file

I have a file which has the first blank line: sundev22$cat /t1/bin/startallocs /t1/bin/startallocsys 123 sundev22$ Is there a command to remove this first blank line? Thanks for help -A (4 Replies)
Discussion started by: aoussenko
4 Replies

9. Shell Programming and Scripting

delete blank space in begining of line

Hi All, below is my data file file.txt $$0 ServerA LAN1 AAA IT01 04/30/2008 09:16:26 $$0 ServerB LAN1 AAA IT02 04/30/2008 09:16:26 here $ is a blank space how to delete first 2 blank spaces in a file. (4 Replies)
Discussion started by: karthikn7974
4 Replies

10. Programming

how to insert and delete characters in the middle of file

I have a problem that I want to insert and delete some chars in the middle of a file. fopen() and fdopen() just allow to append at the end. Is there any simple method or existing library that allow these actions? Thanks in advance.:confused: (7 Replies)
Discussion started by: ivancheung
7 Replies
Login or Register to Ask a Question