Sponsored Content
Top Forums Shell Programming and Scripting Manipulating sed Direct Input to Direct Output Post 302760155 by Don Cragun on Wednesday 23rd of January 2013 12:50:35 PM
Old 01-23-2013
Quote:
Originally Posted by the0nion
Wow....that was quick..
Your 2nd syntax, is it something to be read as,
"find <123:abc:>" then replace 2nd occurance of ":" with ":$" ?
Yes. I would have stated how it behaves as: If a line contains the string "123:abc:" change the 2nd occurrence of ":" on that line to ":$" and then print the modified line.

Quote:
I just came up with another issue. the /I flag

I somehow cant seem to combine /I and /2p together.
I also need to change all my ":" to ",", just for output sake.
The standards don't have an I flag for the sed s command. The Mac OS X system I use when testing stuff I post on this forum doesn't have an I flag for th sed s command. The Linux man sed man page in this forum doesn't mention any flags but says to look for another document that I don't have to determine how sed works on Linux.

If you can tell me what the I flag is supposed to do, I may be able to help, but I have no idea what it does nor why you would want to use it.

I missed the part about changing colons to commas. I still don't have a clear statement of what you're really trying to do. So, back to my original posting:

If you just want to add a $ after the 2nd colon and change colons to commas in each line, try:
Code:
sed 's/:/,/;s/:/,$/' input_file

If you just want to do that on a line that starts with 123:abc: and only print lines that sed modifies, try:
Code:
sed -n 's/:/,/;/123,abc:/s/:/,$/p' input_file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to direct awk output to expr?

Is there any way to combine the following two statements into one? I can't figure out how to get expr to take input from the output of the awk call - I've tried piping the output of the awk call into the expr call, and tried using a 'Here' document, nothing seems to work. export CNT=`wc -l... (4 Replies)
Discussion started by: jvander
4 Replies

2. UNIX for Dummies Questions & Answers

direct output to a file then email it

Ok so i have this script and I dont know how to have the output go to a file and then email that file to someone. #!/bin/ksh print "AL" print "AM" print "AN" print "RL\n" nawk '/PROD/ {print $3, $2}' /home/user/switch_listtest | sort -k1,2 print "End of Report" Thank you in... (2 Replies)
Discussion started by: llsmr777
2 Replies

3. Shell Programming and Scripting

Direct the output of a script to a log file

Hi, I have a script to compare 2 files. file1=$1 file2=$2 num_of_records_file1=`awk ' END { print NR } ' $file1` num_of_records_file2=`awk ' END { print NR } ' $file2` i=1 while do sed -n "$i"p $file1 > file1_temp sed -n "$i"p $file2 > file2_temp diff file1_temp... (5 Replies)
Discussion started by: autosys_nm
5 Replies

4. Shell Programming and Scripting

how to direct scp output to a file in bash shell or script

I can run this from the command line: scp -i identfile /path/file_to_send remotelogin@remotebox:/path_to_put_it/file_to_send and I get: file_to_send 100% |***************************************************************************| 0 00:00 but if I do: scp -i identfile... (6 Replies)
Discussion started by: NewSolarisAdmin
6 Replies

5. Shell Programming and Scripting

Direct input to a script from a file

Hi all, I have a script which checks on my jobs that run on some cluster. The script, "script.sh", takes as an input the job-id for the job to checked. Sometimes I have 100s of jobs and I want to check them. I could put these job-ids into a file, each id in its own line. The script would ask... (2 Replies)
Discussion started by: faizlo
2 Replies

6. Shell Programming and Scripting

Connect:Direct

Hello all, I have a requirement to transfer files to mainframe usinf NDM connect:direct. So can anybody provide me a sample shell script on how to call a connect;direct script by providing filename as a parameter please? Thanks, Ajay (0 Replies)
Discussion started by: ajaykumar4534
0 Replies

7. Shell Programming and Scripting

sed substitution or awk, need to direct change the file

I want change the file when the line contains $(AA) but NOT contains $(BB), then change $(AA) to $(AA) $(BB) eg: $(AA) something $(AA) $(BB) something (7 Replies)
Discussion started by: yanglei_fage
7 Replies

8. UNIX for Dummies Questions & Answers

Output of ssh command from localhost - direct to local file.

Hi, i'm trying to gather details from remote hosts and want them to be written to my local linux machine from where i'm using SSH. My command looks some thing like this ssh -q remotehost 'bash -s' <command.txt where command.txt is a file in my local machine containing ps -ef |grep httpd |... (1 Reply)
Discussion started by: poga
1 Replies

9. Shell Programming and Scripting

Disk Space Script to direct output

Hi, I am working on Sun Solaris 5.10 and want to direct the output from a disk space check script to an output file; #!/bin/bash CURRENT=$(df -k /log/logs | grep /log/logs | awk '{ print $5}' | sed 's/%//g') THRESHOLD=30 if ; then echo "Remaining free space is low" > output.txt else... (10 Replies)
Discussion started by: SSKAAB
10 Replies

10. Shell Programming and Scripting

For loop in bash - Direct output to two files

Hello all, i have a code in which when doing a for loop, i need to direct the output to two files, one just a single output, the other to always append (historical reasons). So far i managed to do the following, which is working, but am still considering it as "dirty". ... (4 Replies)
Discussion started by: nms
4 Replies
SHTOOL-SUBST.TMP(1)					      GNU Portable Shell Tool					       SHTOOL-SUBST.TMP(1)

NAME
shtool-subst - GNU shtool sed(1) substitution operations SYNOPSIS
shtool subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning] [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup ext] [-e|--exec cmd] [-f|--file cmd-file] [file] [file ...] DESCRIPTION
This command applies one or more sed(1) substitution operations to stdin or any number of files. OPTIONS
The following command line options are available. -v, --verbose Display some processing information. -t, --trace Enable the output of the essential shell commands which are executed. -n, --nop No operation mode. Actual execution of the essential shell commands which would be executed is suppressed. -w, --warning Show warning on substitution operation resulting in no content change on every file. The default is to show a warning on substitution operations resulted in no content change on all files. -q, --quiet Suppress warning on substitution operation resulting in no content change. -s, --stealth Stealth operation. Preserve timestamp on file. -i, --interactive Enter interactive mode where the user has to approve each operation. -b, --backup ext Preserve backup of original file using file name extension ext. Default is to overwrite the original file. -e, --exec cmd Specify sed(1) command directly. -f, --file cmd-file Read sed(1) command from file. EXAMPLE
# shell script shtool subst -i -e 's;(c) ([0-9]*)-2000;(c) 1-2001;' *.[ch] # RPM spec-file %install shtool subst -v -n -e 's;^(prefix=).*;1 $RPM_BUILD_ROOT%{_prefix};g' -e 's;^(sysconfdir=).*;1 $RPM_BUILD_ROOT%{_prefix}/etc;g' `find . -name Makefile -print` make install HISTORY
The GNU shtool subst command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 2001 for GNU shtool. It was prompted by the need to have a uniform and convenient patching frontend to sed(1) operations in the OpenPKG package specifications. SEE ALSO
shtool(1), sed(1). 18-Jul-2008 shtool 2.0.8 SHTOOL-SUBST.TMP(1)
All times are GMT -4. The time now is 02:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy