The UNIX and Linux Forums  


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
find and replace command in one line using one command vasikaran UNIX for Dummies Questions & Answers 10 08-20-2008 11:40 AM
using sed command to replace multiple lines radha.kalivar Shell Programming and Scripting 1 07-10-2007 11:36 AM
vi command - replace tictactoe UNIX for Dummies Questions & Answers 1 09-16-2006 10:33 PM
Command to replace character HLee1981 UNIX for Dummies Questions & Answers 5 10-17-2005 02:27 AM
replace text in a file from the command line... dudboy UNIX for Dummies Questions & Answers 1 09-04-2001 03:31 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-21-2007
sudhish sudhish is offline
Registered User
  
 

Join Date: Jun 2007
Location: India, Kerala
Posts: 10
How I can replace this command --need help

Hi,

can I delate first line in a file without opening a file.

Normal unix "sed -i '1d' $path/cash.log" command is working fine, but my windows application not supporting latest version of sed, I also tried to download latest version of sed.exe but failed to find one.

I am in a process of implement a buffer mechanism using following script

#!/bin/sh
path=C:/APPS/Tivoli/bin/w32-ix86/TME/TEC/scripts
set -x
exec 2> $path/SMS_LOG1.log
Cash_count=`more $path/cash.log |wc -l`
while [ "$Cash_count" != "0" ]
do
sms=`head -1 $path/cash.log`
echo "#MSG#$sms" >>$path/output
sleep 5
sed -i '1d' $path/cash.log
Cash_count=`more $path/cash.log |wc -l`
#echo "Cash_count: $Cash_count"
done < $path/cash.log


Please help me on this.


Thanks in advance
Regards
Sudhish
  #2 (permalink)  
Old 06-21-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958

Code:
awk ' NR > 1 { print > "newfile.back" }' currentfile

  #3 (permalink)  
Old 06-21-2007
sudhish sudhish is offline
Registered User
  
 

Join Date: Jun 2007
Location: India, Kerala
Posts: 10
but I what to delete the first line

Hi,

awk ' NR > 1 { print > "newfile.back" }' currentfile

It is working fine, but I what to delete the first line since it is loop command I cant replace the file.
Thanks in advance

Regards
Sudhish
  #4 (permalink)  
Old 06-21-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695

Code:
tail +2 input_file > output_file

  #5 (permalink)  
Old 06-21-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958

Code:
It is working fine, but I what to delete the first line since it is loop command I cant replace the file.
Thanks in advance


If you had to process within a loop,
this might help,

awk command;
( you have the new file )
mv new_file old_file

Last edited by matrixmadhan; 06-21-2007 at 10:14 AM.. Reason: typo
  #6 (permalink)  
Old 06-21-2007
sudhish sudhish is offline
Registered User
  
 

Join Date: Jun 2007
Location: India, Kerala
Posts: 10
Deletion of first line is the problem

Hi,
Let me explain my requirement
1. $path/cash.log is a cash file, I can’t rename it because it content is loaded by another script
2. This script will send SMS until cash.log file become empty also it will continue check for the messages, start sending sms as soon as the message comes
3. Script can only take first line of the cash.log file and send SMS
4. Then I have to delete the first line, other wise script will always send same message only

Deletion of first line is the problem

Thanks in advance
Sudhish
  #7 (permalink)  
Old 06-21-2007
sudhish sudhish is offline
Registered User
  
 

Join Date: Jun 2007
Location: India, Kerala
Posts: 10
Deletion of first line is the problem

Hi,

Let me explain my requirement

1. $path/cash.log is a cash file, I can’t rename it because it content is loaded by another script
2. This script will send SMS until cash.log file become empty also it will continue check for the messages, start sending sms as soon as the message comes
3. Script can only take first line of the cash.log file and send SMS
4. Then I have to delete the first line, other wise script will always send same message only

Deletion of first line is the problem

Thanks in advance
Sudhish
Closed Thread

Bookmarks

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 12:07 PM.


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