Sponsored Content
Top Forums Shell Programming and Scripting Print pipe separated list as line by line in Korn Shell Post 302566900 by Corona688 on Friday 21st of October 2011 11:45:21 AM
Old 10-21-2011
Put it in quotes.

Code:
STR="a|b|c|d|e"

Otherwise, it will assume they're pipes between commands.

To print them one per line:

Code:
STR="a|b|c|d|e"
OLDIFS="$IFS"
IFS="|"
printf "%s\n" $STR
IFS="$OLDIFS"

Changing the special IFS variable to "|" makes unquoted strings split on |, so $STR becomes a b c d e which, fed into printf "%s\n", prints each string on its own line.

Then you set IFS back to normal because you probably don't want it as | all the time.
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Miniature Shell - IO Redirection and Pipe line filters

hi, I was trying to write a miniature shell (ie, command line interpreter) to implement the features like 'IO Redirection' and 'Pipe line fileters'. Can anyone help me with sample shell sript to implement the above features. cheers supong (2 Replies)
Discussion started by: supong
2 Replies

2. Shell Programming and Scripting

To print a specific line in Shell or awk.

Hi, I want to echo the 15th line from a file named as abc.txt, also i want to echo only the values in that line not the line number. Thanks in advance:) (4 Replies)
Discussion started by: tushar_tus
4 Replies

3. Shell Programming and Scripting

Append line that does not contain pipe to it previous line

Hi All, I have a file which contains data as below When we see no pipe character in the line. append those lines to the previous line with pipe character till we get the next line with pipe character with ~(concat with ~) Input file looks like: 1080530944|001|john.l.bonner|Acknowledge|CN... (11 Replies)
Discussion started by: ainuddin
11 Replies

4. Shell Programming and Scripting

how to convert a line to columns, separated by | (pipe)

Hi, Plz help. input line 1;20100403;400|2;20100403;4|3;20290903;400|4;20290903;0|5;20290903;0|9;20100304;0|10;20100304;0|11;20100402;0|18;20100304;0 expected output 1;20100403;400 2;20100403;4 3;20290903;400 4;20290903;0 5;20290903;0 9;20100304;0 10;20100304;0 11;20100402;0... (4 Replies)
Discussion started by: suresh3566
4 Replies

5. Shell Programming and Scripting

delete new line character ( - ) , korn shell

Hi guys , i need help so bad on this issue.. Basically i have to delete the line continuation symbol of first column variable and add the truncated part of that word in next line to first line. here i written sample 3 lines but originally i have bunch of lines in that file. client1_day- ... (3 Replies)
Discussion started by: chrismorgan
3 Replies

6. Shell Programming and Scripting

Korn Shell script to insert at specific line

Hi, I am trying to put together a Korn Shell script to insert at a specific line. The system we use is SunOS 5.10 I can get the line number by using:- num=`sed -n '/export ENV/=' ./tmp.file` Not getting much headway using the above variable's value to insert - export SYBASE=/opt/sybase15... (5 Replies)
Discussion started by: aj8200
5 Replies

7. Shell Programming and Scripting

Use less pipe for grep or awk sed to print the line not include xx yy zz

cat file |grep -v "xx" | grep -v "yy" |grep -v "zz" (3 Replies)
Discussion started by: yanglei_fage
3 Replies

8. Shell Programming and Scripting

[Solved] How to refer more than 9 command line inputs for a scripts in korn shell?

Hi all, I have a script which should take more than 9 command line inputs while running. Likescript.sh a s d f g h j j k l o p i u y t r e w Now in the script if I have to access one of the input which is at position after 9, in this case say 'p' then how can I do that? echo $12 will not work... (15 Replies)
Discussion started by: pat_pramod
15 Replies

9. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

10. UNIX for Beginners Questions & Answers

Reading a file line by line and print required lines based on pattern

Hi All, i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field. i am using centos 7 Operating system. want to read below file. # cat /tmp/d5 NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Discussion started by: balu1234
4 Replies
BuildStrings(1) 					    BSD General Commands Manual 					   BuildStrings(1)

NAME
/usr/bin/BuildStrings -- Generate header (.h) or resource (.r) file from text files SYNOPSIS
/usr/bin/BuildStrings [-define variable] [-header] [-attributes attributeList] [-type filekind] -id ResID -in path -out path DESCRIPTION
The /usr/bin/BuildStrings command translates a text file into a resource or header file for use in localizing your Carbon application. The input file is a series of newline-separated pairs of newline-separated strings. Each pair of strings represents the "base" string and the localized equivalent. When generating a resource file, /usr/bin/BuildStrings generates a STR# resource containing only the localized equiva- lents (which must be enclosed in double quotes in the source file). When generating the header file, /usr/bin/BuildStrings generates a C header file with #define directives for each of the base strings (which must be valid C preprocessor symbols) equating each to the ordinal number of the string in the STR# resource. Your C/C++ source code can use these preprocessor macros, along with standard Resource Manager calls (like GetIndString) to load the appropriate localized string. The source file may include #ifdef/#endif (or #ifndef/#endif) directives to conditionally include different pairs of strings, e.g. for debug- ging builds or different versions. Note that these are the only preprocessor directives allowed in the source file. When generating a resource file, you can set the resource ID and attributes of the STR# resource by providing /usr/bin/BuildStrings with the appropriate command-line options. You can use /usr/bin/BuildStrings with several different sets of strings in the same application, for example, error strings and warning strings. The -type argument customizes some #defines in the generated header file so there are no conflicts. The /usr/bin/BuildStrings command accepts the following arguments: -header Generate a header file. If not provided, default is resource file format. Note that the file extension is not provided automati- cally; your output file name must have the appropriate .h or .r extension. -define variable Defines variable for use in #ifdef or #ifndef conditionals. No value may be assigned to variable. This argument may be repeated for any number of variables. -id ResID The resource ID for the STR# resource. There is no support for setting the resource name. -attributes attribute Resource attributes for the STR# resource definition (such as locked, preload, etc.) These are provided after the resource name in the resource definition. This argument may be repeated for any number of attributes. It is ignored if generating a header. -type filekind Customizes three preprocessor variables (MinValidFoo, MaxValidFoo, FooRsrcID) #defined in a generated header file. Note that if this argument is not provided, the default is the literal string "(null)", which will cause compile errors in the header file. -in path The input file, a set of newline-separated pairs of newline-separated strings. The first string of the pair is ignored for the resource file (but is provided in a comment) and is used as the preprocessor symbol in the header file. The second string of the pair is used as the resource string in the resource file and is ignored in the header file (but is provided in a comment), and must be enclosed in double-quotes in your source file. -out path The output file. Note that you should provide the appropriate file extension; it is not provided automatically according to the -header flag. SEE ALSO
Rez(1), DeRez(1) Mac OS X April 12, 2004 Mac OS X
All times are GMT -4. The time now is 07:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy