Sponsored Content
Top Forums Shell Programming and Scripting Help substituting text in a file having a single line but no newline char Post 302449026 by kurumi on Friday 27th of August 2010 11:07:16 PM
Old 08-28-2010
Code:
exec 6<"myfile"
while read -r LINE<&6
do
  LINE="${LINE/alvan23/alvan4}"
  echo "$LINE"
done > tmp
exec 6<&-
mv tmp myfile

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Substituting carriage return follwed by newline character - HELP!

Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the line since I need to transform my file into an Excel report. Thus my idea is to... (1 Reply)
Discussion started by: djkane
1 Replies

2. Shell Programming and Scripting

Substituting carriage return followed by newline character - HELP

-------------------------------------------------------------------------------- Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the... (14 Replies)
Discussion started by: djkane
14 Replies

3. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies

4. Shell Programming and Scripting

cutting long text by special char around 100 byte and newline

Regard, How can i cut the text by special char(|) around 100 byte and write the other of the text at newline using Perl. ... (3 Replies)
Discussion started by: Shawn, Lee
3 Replies

5. Shell Programming and Scripting

Shell to remove a newline char from selected rows in a file.

Greetings! Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell? Input is like abcd1234 xyzd1234 abcd a1b2c3d4 abcd1234 xyzd1234 xx abcd1234 Expected output - abcd1234xyzd1234 abcda1b2c3d4abcd1234xyzd1234 xxabcd1234 ... (3 Replies)
Discussion started by: mailme0205
3 Replies

6. UNIX for Dummies Questions & Answers

Append a line to single column text file

I would like to add a line to the end of a single column text file. How do I go about doing that? Input: BEGIN 1 2 3 Output: BEGIN 1 2 3 END Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

8. Shell Programming and Scripting

Deleting newline and making output in single line with spaces

HI I have a file line vi Input 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

9. UNIX for Dummies Questions & Answers

Replace the unexpected newline char with space in a Fixed width file

Input eg: Ouput Expected. The #rd line had the unexpted new line, which need to be replaced with space. I was planing to go with checking the length of each line using awk and if the length is less than the defeined limit, (12 in above case) will replace the newline with space. ... (5 Replies)
Discussion started by: deepakwins
5 Replies
SyncExec(3pm)						User Contributed Perl Documentation					     SyncExec(3pm)

NAME
Proc::SyncExec - Spawn processes but report exec() errors SYNOPSIS
# Normal-looking piped opens which properly report exec() errors in $!: sync_open WRITER_FH, "|command -with args" or die $!; sync_open READER_FH, "command -with args|" or die $!; # Synchronized fork/exec which reports exec errors in $!: $pid = sync_exec $command, @arg; $pid = sync_exec $code_ref, $cmd, @arg; # run code after fork in kid # fork() which retries if it fails, then croaks() if it still fails. $pid = fork_retry; $pid = fork_retry 100; # retry 100 times rather than 5 $pid = fork_retry 100, 2; # sleep 2 rather than 5 seconds between # A couple of interfaces similar to sync_open() but which let you # avoid the shell: $pid = sync_fhpopen_noshell READERFH, 'r', @command; $pid = sync_fhpopen_noshell WRITERFH, 'w', @command; $fh = sync_popen_noshell 'r', @command_which_outputs; $fh = sync_popen_noshell 'w', @command_which_inputs; ($fh, $pid) = sync_popen_noshell 'r', @command_which_outputs; ($fh, $pid)= sync_popen_noshell 'w', @command_which_inputs; DESCRIPTION
This module contains functions for synchronized process spawning with full error return. If the child's exec() call fails the reason for the failure is reported back to the parent. These functions will croak() if they encounter an unexpected system error, such as a pipe() failure or a repeated fork() failure. Nothing is exported by default. fork_retry [max-retries [sleep-between]] This function runs fork() until it succeeds or until max-retries (default 5) attempts have been made, sleeping sleep-between seconds (default 5) between attempts. If the last fork() fails fork_retry croak()s. sync_exec [code] command... This function is similar to a fork()/exec() sequence but with a few twists. sync_exec does not return until after the fork()ed child has already performed its exec(). The synchronization this provides is useful in some unusual circumstances. Normally the pid of the child process is returned. However, if the child fails its exec() sync_exec returns undef and sets $! to the reason for the child's exec() failure. Since the @cmd array is passed directly to Perl's exec() Perl might choose to invoke the command via the shell if @cmd contains only one element and it looks like it needs a shell to interpret it. If this happens the return value of sync_exec only indicates whether the exec() of the shell worked. The optional initial code argument must be a code reference. If it is present it is run in the child just before exec() is called. You can use this to set up redirections or whatever. If code returns false no exec is performed, instead a failure is returned using the current $! value (or EINTR if $! is 0). If the fork() fails or if there is some other unexpected system error sync_exec croak()s rather than returning. sync_fhpopen_noshell fh type cmd [arg]... This is a popen() but it never invokes the shell and it uses sync_exec() under the covers. See "sync_exec". The type is either 'r' to read from the process or 'w' to write to it. The return value is the pid of the forked process. sync_popen_noshell type cmd arg... This is like sync_fhpopen_noshell, but you don't have to supply the filehandle. If called in an array context the return value is a list consisting of the filehandle and the PID of the child. In a scalar context only the filehandle is returned. sync_open fh [open-spec] This is like a Perl open() except that if a pipe is involved and the implied exec() fails sync_open() fails with $! set appropriately. See "sync_exec". Like sync_exec, sync_open croak()s if there is an unexpected system error (such as a failed pipe()). Also like sync_exec, if you use a command which Perl needs to use the shell to interpret you'll only know if the exec of the shell worked. Use sync_fhpopen_noshell or sync_exec to be sure that this doesn't happen. AUTHOR
Roderick Schertler <roderick@argon.org> SEE ALSO
perl(1). perl v5.8.8 2005-02-04 SyncExec(3pm)
All times are GMT -4. The time now is 04:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy