The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Script for deleting the first line in a file badrimohanty Shell Programming and Scripting 3 06-18-2009 11:26 AM
shell script reqd - deleting files venkatesht Shell Programming and Scripting 2 12-19-2008 01:15 PM
Deleting column from a flatfile with delimiter rsprabha Shell Programming and Scripting 5 10-03-2008 04:18 AM
Urgent help required in deleting a line without opening a file usinga shell script naan Shell Programming and Scripting 6 07-20-2006 03:42 AM
shell script: deleting files from a directory onlyc Shell Programming and Scripting 1 07-09-2006 06:41 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #8 (permalink)  
Old 06-23-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
and what have you tried?

---------- Post updated at 07:37 PM ---------- Previous update was at 07:23 PM ----------

Code:
grep '^[A-Z]' inputfile > newfile
awk '/^[A-Z]/ {print}' inputfile > newfile
  #9 (permalink)  
Old 06-23-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 517
Code:
perl -pi -e 's/^.*\n$// if (unpack "A5") eq ""' filename
tyler_durden
  #10 (permalink)  
Old 06-23-2009
pa.chidhambaram pa.chidhambaram is offline
Registered User
  
 

Join Date: Feb 2008
Location: Nagercoil
Posts: 10
Quote:
Originally Posted by dinesh1985 View Post
input file
First Name - position from 1-5
Last Name- position 6-10
Age-Position 11-12
Say above is the format of input file.
Example:
DINESKUMAR21
SACHISHAH 23
23
GURUNTARIM22

In the above example,in the 3 rd record Name is missing. Now while reading the file line by line,I want to delete the 3 rd line during validation.

---------- Post updated at 08:47 AM ---------- Previous update was at 08:46 AM ----------

for the third line blankspaces will be present before 23
Hi,
You can use the below command to delete the invalid line.

cat data | awk '{ if(substr($1,1,5)!="" && substr($1,6,10)!="" && substr($1,11,12)!="") print $1}' > new_filtered_file_name.

Where the data is the input file.

Thanks,
chidhu
  #11 (permalink)  
Old 06-23-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 517
Quote:
Originally Posted by pa.chidhambaram View Post
...
You can use the below command to delete the invalid line.

cat data | awk '{ if(substr($1,1,5)!="" && substr($1,6,10)!="" && substr($1,11,12)!="") print $1}' > new_filtered_file_name.

Where the data is the input file.

...
Really ?

Code:
$
$ cat data
DINESKUMAR21
SACHISHAH 23
          23
GURUNTARIM22
$
$ cat data | awk '{ if(substr($1,1,5)!="" && substr($1,6,10)!="" && substr($1,11,12)!="") print $1}'
DINESKUMAR21
GURUNTARIM22
$
$
tyler_durden
  #12 (permalink)  
Old 06-26-2009
dinesh1985 dinesh1985 is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 31
Thanks for your replies ..i ll try it and update

---------- Post updated 06-26-09 at 03:20 AM ---------- Previous update was 06-25-09 at 03:54 AM ----------

I donot want to redirect to any new file. I want to delete the line from the file itself.
I have tried sed -i '3d' to delete the 3rd line. But my shell is not recognizing sed -i.

I have tried sed '3d' <filename> ..it is displaying the file without the 3rd line. But the 3rd line is not permanently deleted. Can anyone please help
  #13 (permalink)  
Old 06-26-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Quote:
Originally Posted by dinesh1985 View Post
Thanks for your replies ..i ll try it and update

---------- Post updated 06-26-09 at 03:20 AM ---------- Previous update was 06-25-09 at 03:54 AM ----------

I donot want to redirect to any new file. I want to delete the line from the file itself.
I have tried sed -i '3d' to delete the 3rd line. But my shell is not recognizing sed -i.

I have tried sed '3d' <filename> ..it is displaying the file without the 3rd line. But the 3rd line is not permanently deleted. Can anyone please help
With a little trick you can redirect the output of sed into the same file

Code:
sed '3d' file | tee file
  #14 (permalink)  
Old 06-26-2009
dinesh1985 dinesh1985 is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 31
Thank you..this is working..
Sponsored Links
Reply

Bookmarks

Tags
sed, shell script, unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0