Sponsored Content
Top Forums Shell Programming and Scripting Splitting text string with "|" pipe delimiters Post 302426804 by Scrutinizer on Thursday 3rd of June 2010 02:52:53 AM
Old 06-03-2010
From a file you can use:
Code:
while IFS='|' read O1 O2 O3 O4 O5 O6 O7 O8; do
  echo "Field O1 is $O1" 
  echo "Field O2 is $O2"
done<listing.txt

From a string you can use:
Code:
string="CUSTNAME|hostname|userid|gecos field|staff|disabled||SUDO"
IFS='|' read O1 O2 O3 O4 O5 O6 O7 O8 <<EOF
$string
EOF

or in bash/ksh93:
Code:
IFS='|' read O1 O2 O3 O4 O5 O6 O7 O8 <<<"$string"



---------- Post updated at 08:52 ---------- Previous update was at 08:45 ----------

In ksh93/bash you can also use arrays, like so:
Code:
 IFS='|' O=( $string )

Code:
$ echo ${O[4]}
staff
$ echo ${O[0]}
CUSTNAME

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

input string="3MMTQSZ348GGMZRQWMJM4SD6M";output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6

input string="3MMTQSZ348GGMZRQWMJM4SD6M" output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M" using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies

2. Shell Programming and Scripting

get string out of text file after "= "

I have a text file like: The name of the project = "Symbion centrifuge" The name of the subsytem = "motor demon" now i would like to read the string after the = into a variable to write it to another file. later use like: sed s/'PROJECTNAME'/"$projectname"/ <header.tex >temp ... (9 Replies)
Discussion started by: vivelafete
9 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

sort text having delimiter with "|" (pipe)

i am having text file below NARGU S S 12358 SALES REP |22| Acccount/s RAJU R B 64253 SALES REP |12| Acccount/s RUKMAN S 32588 SALES REP |10| Acccount/s NARGUND S S 12356... (3 Replies)
Discussion started by: suryanarayana
3 Replies

5. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

6. 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

7. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

8. Shell Programming and Scripting

Need HELP with AWK split. Need to check for "special characters" in string before splitting the file

Hi Experts. I'm stuck with the below AWK code where i'm trying to move the records containing any special characters in the last field to a bad file. awk -F, '{if ($NF ~ /^|^/) print >"goodfile";else print >"badfile"}' filename sample data 1,abc,def,1234,A * 2,bed,dec,342,* A ... (6 Replies)
Discussion started by: shell_boy23
6 Replies

9. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

10. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies
REFER(1)						      General Commands Manual							  REFER(1)

NAME
refer, lookbib - find and insert literature references in documents SYNOPSIS
refer [ option ] ... lookbib [ file ] ... DESCRIPTION
Lookbib accepts keywords from the standard input and searches a bibliographic data base for references that contain those keywords anywhere in title, author, journal name, etc. Matching references are printed on the standard output. Blank lines are taken as delimiters between queries. Refer is a preprocessor for nroff or troff(1) that finds and formats references. The input files (standard input default) are copied to the standard output, except for lines between .[ and .] command lines, which are assumed to contain keywords as for lookbib, and are replaced by information from the bibliographic data base. The user may avoid the search, override fields from it, or add new fields. The reference data, from whatever source, are assigned to a set of troff strings. Macro packages such as ms(7) print the finished reference text from these strings. A flag is placed in the text at the point of reference; by default the references are indicated by numbers. The following options are available: -ar Reverse the first r author names (Jones, J. A. instead of J. A. Jones). If r is omitted all author names are reversed. -b Bare mode: do not put any flags in text (neither numbers nor labels). -cstring Capitalize (with CAPS SMALL CAPS) the fields whose key-letters are in string. -e Instead of leaving the references where encountered, accumulate them until a sequence of the form .[ $LIST$ .] is encountered, and then write out all references collected so far. Collapse references to the same source. -kx Instead of numbering references, use labels as specified in a reference data line beginning %x; by default x is L. -lm,n Instead of numbering references, use labels made from the senior author's last name and the year of publication. Only the first m letters of the last name and the last n digits of the date are used. If either m or ,n is omitted the entire name or date respec- tively is used. -p Take the next argument as a file of references to be searched. The default file is searched last. -n Do not search the default file. -skeys Sort references by fields whose key-letters are in the keys string; permute reference numbers in text accordingly. Implies -e. The key-letters in keys may be followed by a number to indicate how many such fields are used, with + taken as a very large number. The default is AD which sorts on the senior author and then date; to sort, for example, on all authors and then title use -sA+T. To use your own references, put them in the format described in pubindex(1) They can be searched more rapidly by running pubindex(1) on them before using refer; failure to index results in a linear search. When refer is used with eqn, neqn or tbl, refer should be first, to minimize the volume of data passed through pipes. FILES
/usr/dict/papers directory of default publication lists and indexes /usr/lib/refer directory of programs SEE ALSO
REFER(1)
All times are GMT -4. The time now is 09:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy