Sponsored Content
Top Forums Shell Programming and Scripting cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Post 302347304 by rakeshawasthi on Tuesday 25th of August 2009 10:46:27 AM
Old 08-25-2009
I know, you should have tried after seeing the previous solution.
Try:

Code:
awk '/^~/ {gsub(/~/,"",$1); gsub(/~/,"",$2); gsub(/~/,"",$3); gsub(/~/,"",$4); print $1","$2","$3","$4}' b

If you are certain there are only 4 fields then you can do it using $0...
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Post Here to Contact Site Administrators and Moderators

Suggestion: adding two new groups "sed" and "awk"

Majority of the questions are pertaining file/string parsing w.r.t sed or awk It would be nice to have these two as their own sub category under shell-programming-scripting which can avoid lot of duplicate posts. (1 Reply)
Discussion started by: jville
1 Replies

6. Shell Programming and Scripting

Awk,sed : change every 2nd field ":" to "|"

Hi Experts, I have a string with colon delimited, want 2nd colon to be changed to a pipe. data: 101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3: I am trying with sed, but can change only 1 occurance: echo "101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3:" | sed 's/:/|/2'... (5 Replies)
Discussion started by: rveri
5 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

9. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies
regexp(3erl)						     Erlang Module Definition						      regexp(3erl)

NAME
regexp - Regular Expression Functions for Strings DESCRIPTION
Note: This module has been obsoleted by the re module and will be removed in a future release. This module contains functions for regular expression matching and substitution. EXPORTS
match(String, RegExp) -> MatchRes Types String = RegExp = string() MatchRes = {match,Start,Length} | nomatch | {error,errordesc()} Start = Length = integer() Finds the first, longest match of the regular expression RegExp in String . This function searches for the longest possible match and returns the first one found if there are several expressions of the same length. It returns as follows: {match,Start,Length} : if the match succeeded. Start is the starting position of the match, and Length is the length of the matching string. nomatch : if there were no matching characters. {error,Error} : if there was an error in RegExp . first_match(String, RegExp) -> MatchRes Types String = RegExp = string() MatchRes = {match,Start,Length} | nomatch | {error,errordesc()} Start = Length = integer() Finds the first match of the regular expression RegExp in String . This call is usually faster than match and it is also a useful way to ascertain that a match exists. It returns as follows: {match,Start,Length} : if the match succeeded. Start is the starting position of the match and Length is the length of the matching string. nomatch : if there were no matching characters. {error,Error} : if there was an error in RegExp . matches(String, RegExp) -> MatchRes Types String = RegExp = string() MatchRes = {match, Matches} | {error, errordesc()} Matches = list() Finds all non-overlapping matches of the expression RegExp in String . It returns as follows: {match, Matches} : if the regular expression was correct. The list will be empty if there was no match. Each element in the list looks like {Start, Length} , where Start is the starting position of the match, and Length is the length of the matching string. {error,Error} : if there was an error in RegExp . sub(String, RegExp, New) -> SubRes Types String = RegExp = New = string() SubRes = {ok,NewString,RepCount} | {error,errordesc()} RepCount = integer() Substitutes the first occurrence of a substring matching RegExp in String with the string New . A & in the string New is replaced by the matched substring of String . & puts a literal & into the replacement string. It returns as follows: {ok,NewString,RepCount} : if RegExp is correct. RepCount is the number of replacements which have been made (this will be either 0 or 1). {error, Error} : if there is an error in RegExp . gsub(String, RegExp, New) -> SubRes Types String = RegExp = New = string() SubRes = {ok,NewString,RepCount} | {error,errordesc()} RepCount = integer() The same as sub , except that all non-overlapping occurrences of a substring matching RegExp in String are replaced by the string New . It returns: {ok,NewString,RepCount} : if RegExp is correct. RepCount is the number of replacements which have been made. {error, Error} : if there is an error in RegExp . split(String, RegExp) -> SplitRes Types String = RegExp = string() SubRes = {ok,FieldList} | {error,errordesc()} Fieldlist = [string()] String is split into fields (sub-strings) by the regular expression RegExp . If the separator expression is " " (a single space), then the fields are separated by blanks and/or tabs and leading and trailing blanks and tabs are discarded. For all other values of the separator, leading and trailing blanks and tabs are not discarded. It returns: {ok, FieldList} : to indicate that the string has been split up into the fields of FieldList . {error, Error} : if there is an error in RegExp . sh_to_awk(ShRegExp) -> AwkRegExp Types ShRegExp AwkRegExp = string() SubRes = {ok,NewString,RepCount} | {error,errordesc()} RepCount = integer() Converts the sh type regular expression ShRegExp into a full AWK regular expression. Returns the converted regular expression string. sh expressions are used in the shell for matching file names and have the following special characters: * : matches any string including the null string. ? : matches any single character. [...] : matches any of the enclosed characters. Character ranges are specified by a pair of characters separated by a - . If the first character after [ is a ! , then any character not enclosed is matched. It may sometimes be more practical to use sh type expansions as they are simpler and easier to use, even though they are not as pow- erful. parse(RegExp) -> ParseRes Types RegExp = string() ParseRes = {ok,RE} | {error,errordesc()} Parses the regular expression RegExp and builds the internal representation used in the other regular expression functions. Such representations can be used in all of the other functions instead of a regular expression string. This is more efficient when the same regular expression is used in many strings. It returns: {ok, RE} if RegExp is correct and RE is the internal representation. : {error, Error} if there is an error in RegExpString . : format_error(ErrorDescriptor) -> Chars Types ErrorDescriptor = errordesc() Chars = [char() | Chars] Returns a string which describes the error ErrorDescriptor returned when there is an error in a regular expression. REGULAR EXPRESSIONS
The regular expressions allowed here is a subset of the set found in egrep and in the AWK programming language, as defined in the book, The AWK Programming Language, by A. V. Aho, B. W. Kernighan, P. J. Weinberger . They are composed of the following characters: c : matches the non-metacharacter c . c : matches the escape sequence or literal character c . . : matches any character. ^ : matches the beginning of a string. $ : matches the end of a string. [abc...] : character class, which matches any of the characters abc... Character ranges are specified by a pair of characters separated by a - . [^abc...] : negated character class, which matches any character except abc... . r1 | r2 : alternation. It matches either r1 or r2 . r1r2 : concatenation. It matches r1 and then r2 . r+ : matches one or more r s. r* : matches zero or more r s. r? : matches zero or one r s. (r) : grouping. It matches r . The escape sequences allowed are the same as for Erlang strings:  : backspace f : form feed : newline (line feed) : carriage return : tab e : escape v : vertical tab s : space d : delete ddd : the octal value ddd xhh : The hexadecimal value hh . x{h...} : The hexadecimal value h... . c : any other character literally, for example \ for backslash, " for ") To make these functions easier to use, in combination with the function io:get_line which terminates the input line with a new line, the $ characters also matches a string ending with "... " . The following examples define Erlang data types: Atoms [a-z][0-9a-zA-Z_]* Variables [A-Z_][0-9a-zA-Z_]* Floats (+|-)?[0-9]+.[0-9]+((E|e)(+|-)?[0-9]+)? Regular expressions are written as Erlang strings when used with the functions in this module. This means that any or " characters in a regular expression string must be written with as they are also escape characters for the string. For example, the regular expression string for Erlang floats is: "(\+|-)?[0-9]+\.[0-9]+((E|e)(\+|-)?[0-9]+)?" . It is not really necessary to have the escape sequences as part of the regular expression syntax as they can always be generated directly in the string. They are included for completeness and can they can also be useful when generating regular expressions, or when they are entered other than with Erlang strings. Ericsson AB stdlib 1.17.3 regexp(3erl)
All times are GMT -4. The time now is 05:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy