Sponsored Content
Top Forums Shell Programming and Scripting replacing single space in argument Post 302115506 by zazzybob on Wednesday 25th of April 2007 07:22:43 AM
Old 04-25-2007
To simplify, pass everything as 1 quoted argument, then have the script process it, e.g.
Code:
$ cat > space_parsing
#!/bin/bash

set -- $( echo "$1" | sed 's/\([^ ]\) \([^ ]\)/\1_\2/g' | tr -s ' ' )

echo "$@"

echo "$1"

echo "$4"

exit 0
^D
$ chmod +x !$
chmod +x space_parsing
$ ./space_parsing "foo    bar    baz    hello hi    foo   hello hi again"
foo bar baz hello_hi foo hello_hi_again
foo
hello_hi

Cheers,
ZB
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing a single quote

Hi there I have a data file like so below 'A/1';'T100002';'T100002';'';'01/05/2004';'31/05/2004';'01/06/2004';'08/06/2004';'1.36';'16';'0.22';'0';'0';'1.58';'0';'0';'0';'0';'0';'0';'clientes\resumen\200405\resumen_T100002_T100002_1.pdf';'';'0001';'S';'20040501';'';'02';'0';'S';'N'... (3 Replies)
Discussion started by: rjsha1
3 Replies

2. Shell Programming and Scripting

getopts ... only allow a single instance of an argument?

Hi there, if i have a simple getopts like below ...how can i make it so that if somebody enters more than one -g argument for example, it will error with a " you cannot enter more than one -g" or something like that.? I want to only allow one instance of a -g or a -h etc .. while getopts... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

3. Shell Programming and Scripting

getopts : two values to a single argument ?

Hi Gurus I am trying to figure out (with not much success) how to pass two values to a single getopts argument ... for example ./script -a Tuesday sausagesThe $OPTARG variable seems to only get populated with the first argument. What im looking to do is to process the first argument (i.e.make... (6 Replies)
Discussion started by: rethink
6 Replies

4. Shell Programming and Scripting

Stripping out more than a space from a line, but keep single space.

Hi all, Is there a way to perform the above, I am trying to strip out more than one space from a line, but keep the single space. See below output example. My Name is test test2 test3 test4 test5 My Name is test test2 test3 test4 test5 Please note that the lines would contain... (7 Replies)
Discussion started by: eo29
7 Replies

5. Shell Programming and Scripting

Replacing trailing space with single quote

Platform : RHEL 5.8 I want to end each line of this file with a single quote. $ cat hello.txt blueskies minnie mickey gravity snoopyAt VI editor's command mode, I have used the following command to replace the last character with a single quote. ~ ~ ~ :%s/$/'/gNow, the lines in the... (10 Replies)
Discussion started by: John K
10 Replies

6. UNIX for Dummies Questions & Answers

Replacing double spaces with single space

I am looking for a regular expression that uses sed to replace multiple spaces with single spaces on every line where it is not at the start of the line and not immediately before double slashes ('//') or between quotes ("). In its simplest form, it would look like this: sed -e 's# # #g'... (4 Replies)
Discussion started by: figaro
4 Replies

7. Shell Programming and Scripting

Getopts - space in argument (OPTARG)

Hi, I want to capture space as well from the argument eg: script.ksh -m "Message from xyz" -e "email@xyz.com" script.ksh -m 'Message from xyz' -e 'email@xyz.com' I am parsing using getopts, but for option "m" OPTARG is returning only "Message". Please use code tags next time for... (9 Replies)
Discussion started by: tostay2003
9 Replies

8. Shell Programming and Scripting

Passing multiple value in a single argument in Perl.

Hi all, I have below code through which trying to pick data from specific columns strating from a certain row. #!/usr/bin/perl #This script is to pick the specific fields from a files starting from a specific row # FILE -> Name of the file to be pasd at runtime. # rn -> Number of the... (4 Replies)
Discussion started by: Abhisrajput
4 Replies

9. Shell Programming and Scripting

Replacing Multiple spaces with a single space but excluding few regular expressions

Hi All. Attached are two files. I ran a query and have the output as in the file with name "FILEWITHFOURRECORDS.txt " I didn't want all the spaces between the columns so I squeezed the spaces with the "tr" command and also added a carriage return at the end of every line. But in two... (3 Replies)
Discussion started by: sparks
3 Replies

10. Shell Programming and Scripting

Issue handling single quoted argument in shell script.

Below is my script that works fine and prints the desired output: #!/bin/ksh echo "$1" | while IFS= read -r dirpath do echo "DIRR_PATH:$dirpath" install_dir=$install_dir" "$dirpath done echo "Desired Output:$install_dir" Output: ./loopissue.sh... (10 Replies)
Discussion started by: mohtashims
10 Replies
xstr(1) 						      General Commands Manual							   xstr(1)

Name
       xstr - extract strings from C program

Syntax
       xstr [-c] [-] [file]

Description
       The  command maintains a file strings into which strings in component parts of a large program are hashed.  These strings are replaced with
       references to this common area.	This serves to implement shared constant strings, most useful if they are also read-only.

       The command
       xstr -c name

       will extract the strings from the C source in name, replacing string references by expressions of the form (&xstr[number]) for some number.
       An  appropriate declaration of is prepended to the file.  The resulting C text is placed in the file x.c, to then be compiled.  The strings
       from this file are placed in the strings data base if they are not there already.  Repeated strings  and  strings  which  are  suffices	of
       existing strings do not cause changes to the data base.

       After all components of a large program have been compiled a file xs.c declaring the common space can be created by a command of the form
       xstr

       This xs.c file should then be compiled and loaded with the rest of the program.	If possible, the array can be made read-only (shared) sav-
       ing space and swap overhead.

       The command can also be used on a single file.  A command
       xstr name

       creates files x.c and xs.c as before, without using or affecting any strings file in the same directory.

       It may be useful to run after the C preprocessor if any macro definitions yield strings or if there  is	conditional  code  which  contains
       strings	which may not, in fact, be needed.  The command reads from its standard input when the argument `-' is given.  An appropriate com-
       mand sequence for running after the C preprocessor is:
       cc -E name.c | xstr -c -
       cc -c x.c
       mv x.o name.o

       The command does not touch the file strings unless new items are added, thus can avoid remaking xs.o unless truly necessary.

Options
       -  Reads stdin.

       -c Extracts strings from specified C source (next argument).

Restrictions
       If a string is a suffix of another string in the data base, but the shorter string is seen first by both strings will be placed in the data
       base, when just placing the longer one there will do.

Files
       strings	      Data base of strings
       x.c	 Massaged C source
       xs.c	 C source for definition of array `xstr'
       /tmp/xs*  Temp file when `xstr name' doesn't touch strings

See Also
       mkstr(1)

																	   xstr(1)
All times are GMT -4. The time now is 02:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy