Sponsored Content
Full Discussion: UNIX commands question
Top Forums Shell Programming and Scripting UNIX commands question Post 302938843 by MadeInGermany on Thursday 19th of March 2015 12:17:27 PM
Old 03-19-2015
i and a and c commands need multi-line (not possible in t/csh!), where the previous line ends with a \ character:
Code:
sed '/unix/ i\
Insert a new line
' file.txt

Code:
sed '/unix/ a\
Append a new line
' file.txt

Code:
sed '/unix/ c\
Change to line1\
and line2
' file.txt

They can as well be done by the s (substitute) command.
where the c (change) with a one-line replacement can be done in one line:
Code:
sed '/unix/ s/.*/Change line/' file.txt

To write the changes back to the input file, it is most safe to overwrite it (retaining the inode/owner/permissions):
Code:
sed '...' file.txt > file.txt.new && cp file.txt.new file.txt && rm file.txt.new

or
Code:
cp file.txt file.txt.old && sed '...' file.txt.old > file.txt && rm file.txt.old

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Maingrame to UNIX sending UNIX commands

I want to know if there is a way to send unix commands thru FTP from a mainframe to kick off Autosys Jobs. I just need to send a command from the mainframe to UNIX and have UNIX execute that command. (2 Replies)
Discussion started by: skammer
2 Replies

2. UNIX for Dummies Questions & Answers

Question about batched commands

Hi everyone I am a newbbie in the linux enviroment. My problem is: I have tried to use the at command to compile and keep running a program and close the terminal window. Every time I use the at command I get the next error "Can't open /var/run/atd.pid to signal atd. No atd running?" ... (2 Replies)
Discussion started by: fenixbeta
2 Replies

3. UNIX for Dummies Questions & Answers

Running UNIX commands remotely in Windows box from Unix box – avoid entering password

I am able to run the UNIX commands in a Windows box from a UNIX box through "SSH" functionality. But whenever the SSH connection is established between UNIX and Windows, password for windows box is being asked. Is there a way to avoid asking password whenever the SSH connection is made? Can I... (1 Reply)
Discussion started by: D.kalpana
1 Replies

4. Shell Programming and Scripting

ssh commands in ksh question

Is there a way to shorten these commands? because this script asks for a password 3 times scp -p /usr/local/bin/${script_name} ${servername$iy]}://usr/local/bin/ ssh ${servernames} /usr/local/bin/${script_name} ssh ${servernames} rm -f /usr/local/bin/${script_name} Basically, I'm creating a... (3 Replies)
Discussion started by: pdtak
3 Replies

5. Shell Programming and Scripting

Question about awk commands

what does this mean? cat /etc/passwd | awk -F: '{print $5}' | \ awk -F, '{print $1}' | \ awk '{print tolower($l)};{print tolower($2)}' | \ grep -v '^$' >> local_tmp (1 Reply)
Discussion started by: hin-linux
1 Replies

6. Shell Programming and Scripting

question about shell commands...

Hello, I have the following is a txt file: !!! man.uni.com address 141.000.001 to you.uni.com !!! man.uni.com address 141.000.002 to wae1.uni.com !!! man.uni.com address 141.000.003 to kim2.uni.com I want to get you,wae and kim from the text and put them in a diffrent file in the following... (2 Replies)
Discussion started by: andrew1400
2 Replies

7. Homework & Coursework Questions

Unix commands Help

I am struggling with one of my assignment questions, not sure how to go about coding it question is 2. The fille ~eliwp/marks is a colon separated list of students and their marks. Write a script to process this file printing out the id's of the students that have failed the module.... (2 Replies)
Discussion started by: tina_2010
2 Replies

8. UNIX for Dummies Questions & Answers

Noob scripting question with android ADB commands

Hi I'm pretty new to scripting and I've been googling around looking for an answer but have yet to come up with a proper solution. I work with multiple android devices at a time and I'm looking to simplify my life with a script. Basically I'm looking for a script that takes the device ID's and then... (2 Replies)
Discussion started by: Onyoursix
2 Replies

9. UNIX for Dummies Questions & Answers

Beginner UNIX question. tail and find commands

hey guys, i'm in a unix course.. and while this is a homework question - i did put alittle effort into it. just wanted to ask before trial and error drives me nuts. question 13 has us saving the last 30 characters of a file into another file and question 14 has us saving the list of all the... (1 Reply)
Discussion started by: labelthief
1 Replies

10. Shell Programming and Scripting

UNIX commands question

if ] then rm -rf Can anyone tell me what are they checking in the if loop Please use code tags next time for your code and data. Thanks (2 Replies)
Discussion started by: ramkumar15
2 Replies
RDUP-UP(1)							       rdup								RDUP-UP(1)

NAME
rdup-up - update a directory tree with a rdup archive SYNOPSIS
rdup-up [OPTION]... DIRECTORY DESCRIPTION
With rdup-up you can update an (possibly) existing directory structure with a rdup archive. The rdup archive has to be given to rdup-up's standard input. Username and uids rdup outputs both the username and uid, the receiving system (which may be a totally different system) checks if the username and uid match. If the username and uid don't match the (numeric) uid is used on the file. The same holds true for the groupname and gid. OPTIONS
-n Do a dry-run and do not create anything on disk. -t Create DIRECTORY (ala mkdir -p) if it does not exist. -s N Strip N path components from a pathname. If the resulting pathname is empty after this operation it is skipped. Be careful however with the following structure: /foo /foo/bar /foo/bar/bla.txt /foo/blork/bla.txt With rdup-up -s2 this will leave: <empty> <empty> /bla.txt /bla.txt And the last 'bla.txt' will overwrite the previous one, this will happen without warnings. -r PATH This option is related to the -s option, but works different. The string PATH is removed from (the beginning of) each pathname. With -r /home/backup the pathname /home/backup/bin/mycmd becomes /bin/mycmd. The same could be done with -s 2, but then you need to count the slashes. Note -s is always performed before -r. -v Be more verbose and echo the processed files to standard output. -vv Be even more verbose and echo processed file and the uid and gid information to standard output. -T Show a table of contents of the rdup stream received (ala tar -tf -). With -T the directory argument is optional. -T unsets any verbose (-v) options. -h A short help message. -V Show the version. EXIT CODE
rdup-up return a zero exit code on success, otherwise 1 is returned. AUTHOR
Written by Miek Gieben. REPORTING BUGS
Report bugs to <miek@miek.nl>. SEE ALSO
http:/www.miek.nl/projects/rdup/ is the main site of rdup. Also see rdup(1), rdup-tr(1) and rdup-backups(7). COPYRIGHT
Copyright (C) 2005-2010 Miek Gieben. This is free software. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Licensed under the GPL version 3. See the file LICENSE in the source distribution of rdup. 1.1.11 13 Dec 2008 RDUP-UP(1)
All times are GMT -4. The time now is 05:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy