Sponsored Content
Full Discussion: Understanding sed
Top Forums Shell Programming and Scripting Understanding sed Post 302774009 by Scrutinizer on Friday 1st of March 2013 04:06:20 AM
Old 03-01-2013
Hi, the first one deletes the second field only if it consists of one character... It replace the first field and a colon + a character and a colon with the first field (that was captured with \( .. \) and recalled by\1) and two colons

The second replaces any number of non-colons and a colon by a colon, the number two means the it does this with the second occurrence on a line...
This User Gave Thanks to Scrutinizer For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

need further understanding of init.d

I needt o know how what init.d does and how it knows which dameons/applications to turn off and how to restart the applications after reboot. any OS - solaris/hp-ux (1 Reply)
Discussion started by: jigarlakhani
1 Replies

2. Shell Programming and Scripting

understanding the sed command

Guys, I am trying to understand the sed command here. adx001 $ a=/clocal/dctrdata/user/dctrdat1/trdroot/recouncil adx001 $ b=`echo $a | sed 's/\//\\\\\//g'` adx001 $ echo $b \/clocal\/dctrdata\/user\/dctrdat1\/trdroot\/recouncil The sed command i took it from the script. Please... (3 Replies)
Discussion started by: mac4rfree
3 Replies

3. UNIX for Dummies Questions & Answers

Help understanding sed

I am trying to create a basic script that converts an Oracle script into a Sybase script. The only things im changing are Datatypes and the to_char and to_date functions. I am not really 100% sure of the way it works. I have tried running the functions through a loop to replace each word line... (6 Replies)
Discussion started by: Makaer
6 Replies

4. Shell Programming and Scripting

need help understanding mv

I just started shell coding and I'm a bit confused on how 'mv' works can someone explain to me how it works and if i did this correctly. Thanks. echo "Enter Name of the first file:" read file1 #echo $file1 if ; then echo "Sorry, file does not exist." exit 1 ... (16 Replies)
Discussion started by: taiL
16 Replies

5. UNIX for Dummies Questions & Answers

understanding {%/*}/

Hi Gurus: I am trying to understand the following line of code.I did enough of googling to understand but no luck.Please help me understand the follow chunk of code: X=$0 MOD=${X%/*}/env.ksh X is the current script from which I am trying to execute. Say if X=test.ksh $MOD is echoing :... (3 Replies)
Discussion started by: vemana
3 Replies

6. UNIX for Dummies Questions & Answers

understanding sed command

Hi Friends, I need a small help in understanding the below sed command. $ cat t4.txt 1 root 1 58 0 888K 368K sleep 4:06 0.00% init 1 root 1 58 0 888K 368K sleep 4:06 0.00% init last $ sed 's/*$//' t4.txt 1 root 1 58 0 888K ... (3 Replies)
Discussion started by: forroughuse
3 Replies

7. Shell Programming and Scripting

help understanding regex with grep & sed

I have the following line of code that works wonders. I just don't completely understand it as I am just starting to learn regex. Can you help me understand exactly what is happening here? find . -type f | grep -v '^\.$' | sed 's!\.\/!!' (4 Replies)
Discussion started by: trogdortheburni
4 Replies

8. Shell Programming and Scripting

Need your help in understanding this

Hi, I found this in a script and I would like to know how this works Code is here: # var1=PART1_PART2 # var2=${var1##*_} # echo $var2 PART2 I'm wondering how ##* makes the Shell to understand to pick up the last value from the given. (2 Replies)
Discussion started by: sathyaonnuix
2 Replies

9. Shell Programming and Scripting

Need Quick help on Understanding sed Regex

Hi Guys, Could you please kindly explain what exactly the below SED command will do ? I am quite confused and i assumed that, sed 's/*$/ /' 1. It will remove tab and extra spaces .. with single space. The issue is if it is removing tab then it should be Î right .. please assist.... (3 Replies)
Discussion started by: Nandy
3 Replies
getopt(3C)																getopt(3C)

NAME
getopt(), optarg, opterr, optind, optopt - get option letter from argument vector SYNOPSIS
DESCRIPTION
returns the next option letter in argv (starting from that matches a letter in optstring. argc and argv are the argument count and argu- ment array as passed to optstring is a string of recognized option characters; if a character is followed by a colon, the option takes an argument which may or may not be separated from it by whitespace. is the index of the next element of the vector to be processed. It is initialized to 1 by the system, and updates it when it finishes with each element of returns the next option character from argv that matches a character in optstring, if there is one that matches. If the option takes an argument, sets the variable to point to the option argument as follows: o If the option was the last character in the string pointed to by an element of argv, then contains the next element of argv, and is incremented by 2. If the resulting value of is greater than or equal to argc, this indicates a missing option argument, and returns an error indication. o Otherwise, points to the string following the option character in that element of argv, and is incremented by 1. If, when is called, is NULL, or the string pointed to by either does not begin with the character or consists only of the character returns -1 without changing If points to the string returns -1 after incrementing If encounters an option character that is not contained in optstring, it returns the question-mark character. If it detects a missing option argument, it returns the colon character if the first character of optstring was a colon, or a question-mark character otherwise. In either case, sets the variable to the option character that caused the error. If the application has not set the variable to zero and the first character of optstring is not a colon, also prints a diagnostic message to standard error. The special option can be used to delimit the end of the options; -1 is returned, and is skipped. RETURN VALUE
returns the next option character specified on the command line. A colon is returned if detects a missing argument and the first character of optstring was a colon A question-mark is returned if encounters an option character not in optstring or detects a missing argument and the first character of optstring was not a colon Otherwise, returns -1 when all command line options have been parsed. EXTERNAL INFLUENCES
Locale The category determines the interpretation of option letters as single and/or multi-byte characters. International Code Set Support Single- and multibyte character code sets are supported. ERRORS
fails under the following conditions: [EILSEQ] An invalid multibyte character sequence was encountered during option processing. EXAMPLES
The following code fragment shows to process arguments for a command that can take the mutually exclusive options and and the options and both of which require arguments: #include <stdio.h> #include <unistd.h> main (int argc, char *argv[]) { int c; int bflg, aflg, errflg; extern char *optarg; extern int optind, optopt; . . . while ((c = getopt(argc, argv, ":abf:o:")) != -1) switch (c) { case 'a': if (bflg) errflg++; else aflg++; break; case 'b': if (aflg) errflg++; else { bflg++; bproc( ); } break; case 'f': ifile = optarg; break; case 'o': ofile = optarg; break; case ':': /* -f or -o without arguments */ fprintf(stderr, "Option -%c requires an argument ", optopt); errflg++; break; case '?': fprintf(stderr, "Unrecognized option: - %c ", optopt); errflg++; } if (errflg) { fprintf(stderr, "usage: . . . "); exit(2); } for ( ; optind < argc; optind++) { if (access(argv[optind], 4)) { . . . } WARNINGS
Options can be any ASCII characters except colon question mark or null SEE ALSO
getopt(1), thread_safety(5). STANDARDS CONFORMANCE
getopt(3C)
All times are GMT -4. The time now is 12:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy