Sponsored Content
Top Forums Shell Programming and Scripting SED help (remove line::parse again::add line) Post 302142125 by drl on Wednesday 24th of October 2007 12:36:25 PM
Old 10-24-2007
Hi
Quote:
Originally Posted by bakunin
The reason is: sed will read the first line of the input file (which is "file"), apply any rules that might be applicable and then write the result (the changed or not changed line) to <stdout>. This <stdout> is at this moment pointing to "file" and this is why after the first line the file will contain nothing more than exactly that first line - so sed encounters the EOF and thinks it is finished.
I would have explained this behaviour somewhat differently: when the shell begins to process a command line, it will literally remove the characters that involve re-direction. In dealing with re-direction, the shell will "zero" a file that is being re-directed to. If there was data on the file, it will have been erased before the command is executed. The result is that the command -- in this case sed -- will never see any input, because it already has been destroyed. The first read will encounter EOF.

Most of us have fallen into this operational trap. For example, we often want to sort a file onto itself -- just re-ordering data, neither gaining or losing data. So sort has an option to write the output to the input file, but one must use "-o file", and not "> file". The GNU sed allows a similar construction with "in-place" editing, but what actually happens is that sed writes to a temporary file and then renames it at the end. You can see this if you display the inode number (ls -li file) before and after the operation. You'll see that they are different.

The flow-chart of shell operations is displayed in some books, for example, O'Reilly's Learning the bash shell, 2nd, page 177 ff ... cheers, drl
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse Line Using Sed

Hello All, I am new to using sed, and I need to extract from the string data after : delimeter. Can you help me please with the sed command? Here's the input: ipAddress: 10.20.10.11 ioIpAddressNodeB: 10.20.10.10 ioIpAddressNodeA: 10.20.10.9 ipAddress: 0.0.0.0 Expected Output:... (7 Replies)
Discussion started by: racbern
7 Replies

2. Shell Programming and Scripting

sed remove last 10 characters of a line start from 3rd line

hello experts, I need a sed command that remove last 10 characters of a line start from 3rd line. any suggestions? Thanks you (7 Replies)
Discussion started by: minifish
7 Replies

3. UNIX for Advanced & Expert Users

how do you parse 1 line at a time of file1 ie. line(n) each line into new file

File 1 <html>ta da....unique file name I want to give file=>343...</html> <html>da ta 234 </html> <html>pa da 542 </html> and so on... File 2 343 234 542 and so on, each line in File 1 one also corresponds with each line in File 2 I have tried several grep, sed, while .. read, do,... (4 Replies)
Discussion started by: web_developer
4 Replies

4. Shell Programming and Scripting

SED remove line feed and add to certain area

Hi All, I have a xml file and requirement is to remove the line feed and add line feed after some element. <?xml version="1.0" ?> <AUDITRECORDS> <CARF> <HED> <VN1>20090616010622</VN1> <VN2>0</VN2> <VN3>1090</VN3> <VN4>CONFIG_DATA</VN4> ... (8 Replies)
Discussion started by: sreejitnair123
8 Replies

5. Shell Programming and Scripting

Help to Add and Remove Records only from first line/last line

Hi, I need help with a maybe total simple issue but somehow I am not getting it. I am not able to etablish a sed or awk command which is adding to the first line in a text and removing only from the last line the ",". The file is looking like follow: TABLE1, TABLE2, . . . TABLE99,... (4 Replies)
Discussion started by: enjoy
4 Replies

6. Shell Programming and Scripting

Parse configuration file & add line in particular section

Greetings, I recently built a replicated DRBD, Heartbeat, & iSCSI Target Initiator storage server on Ubuntu 10.04 to offer shared storage to server Vmware ESX and Microsoft Clusters. Everything works flawlessly, however I wanted to make a script to create, remove, grow volumes to offer ESX... (6 Replies)
Discussion started by: Aeudian
6 Replies

7. UNIX for Dummies Questions & Answers

Sed to remove only first line erroneously removes last line too

Hello everyone, This is my first posting. I have read the rules of this forum. I have searched many various threads and haven't found one that applies to my situation or suggestions to fix the issue. I do appreciate the help. I am trying to execute a basic UNIX script in a Solaris... (4 Replies)
Discussion started by: dqrgk0
4 Replies

8. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

9. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies
ECACCESS-EVENT-GRANT(1p)				User Contributed Perl Documentation				  ECACCESS-EVENT-GRANT(1p)

NAME
ecaccess-event-grant - Grant usage of an ECaccess Event SYNOPSIS
ecaccess-event-grant -version|-help|-manual ecaccess-event-grant [-debug] [-subscribe] [-notify] event-id user-list DESCRIPTION
Allow managing the Event permissions for a list of user(s). The permissions can be either subscribe, notify, both or none. In order to remove permissions to an Event for a list of users use this command with no -subscribe and -notify options. ARGUMENTS
event-id The identifier of the Event to grant. user-list The user(s) to give/remove the permissions. Multiple users should be separated by a column (e.g. abc,def). OPTIONS
-subscribe The user(s) specified in the user-list will be allowed to subscribe to the event-id (e.g. with the -eventIds option of the ecaccess-job-submit command). -notify The user(s) specified in the user-list will be allowed to send notifications to the event-id (e.g. with the ecaccess-event-send command). -version Display version number and exits. -help Print a brief help message and exits. -manual Prints the manual page and exits. -debug Display the SOAP messages exchanged. EXAMPLES
ecaccess-event-grant -subscribe 167 abc,def,jhi Allow the users abc, def and jhi to subscribe to this Event. ecaccess-event-grant 167 jkl Remove all rights to the Event for the user jkl. SEE ALSO
ecaccess-event-clear, ecaccess-event-delete, ecaccess-event-send, ecaccess-event-list, ecaccess-event-create and ecaccess. perl v5.14.2 2012-04-16 ECACCESS-EVENT-GRANT(1p)
All times are GMT -4. The time now is 02:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy