Sponsored Content
Full Discussion: Set problem with spaces
Top Forums Shell Programming and Scripting Set problem with spaces Post 302851189 by SkySmart on Saturday 7th of September 2013 12:06:59 PM
Old 09-07-2013
Quote:
Originally Posted by Scrutinizer
That is because in addition to your original problem specification you are using command substitution: $( .. ) which will cause the output of the command to be split into fields according to the IFS variable, which defaults to a space, a TAB and a newline. The same would go for variable expansion.

There is a difference between:
Code:
$ set -- hello 'cat dog walk' money elephant
$ echo "$2"
cat dog walk

and
Code:
$ var="hello 'cat dog walk' money elephant"
$ set -- $var
$ echo "$2"
'cat

in the first case there are 4 fields, and no field splitting is performed
in the second case there is field splitting after expansion of the variable "var", which results in 6 fields with the default IFS


--
You could try something like this:
Code:
$ oldIFS=$IFS
$ IFS="
"
$ set -- $(xargs -n1 < infile2443)
$ IFS=$oldIFS
$ echo "$2"
cat dog walk
$

this worked. thank you so much!!!!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

problem with the blank spaces in array

Hi all! i need your help. I'm getting started with this... in need to insert in an array string values. But the thing is that this strings have blank spaces... for example if a want to put "filed1 = " and "field2 = " .... in the array , when i want to print all the fields, it only shows... (4 Replies)
Discussion started by: kamicasse
4 Replies

2. Shell Programming and Scripting

problem with spaces and argument parsing

public class HelloWorld { public static void main(String args) { System.out.println("Welcome, master"); } } and I compiled using javac HelloWorld.java ] Suppose that I execute the following command directly from the shell: java -XX:OnError="gdb - %p" HelloWorld Then it works... (8 Replies)
Discussion started by: fabulous2
8 Replies

3. UNIX for Dummies Questions & Answers

Problem with spaces in directory path

Hi Gurus, I have a requirement. cat /usdd/Sample/"NDDF Plus DB"/"NDDF Descriptive and Pricing"/"NDDF BASICS 3.0"/"Pricing"/1.txt | sed 's/*|*/|/g' | sed 's/^*//'| sed 's/^*//; s/*$//' > temp.txt In unix prompt the above command is reading the file 1.txt and I am... (1 Reply)
Discussion started by: prabhutkl
1 Replies

4. Shell Programming and Scripting

set tab to 4 spaces in vi

Hi, I want to set my tab lenght to 4 spaces instead of 8. And when i press tab instead of inserting tab it should insert 4 spaces. if i do set ts=4 this set tab=4. But this inserts tab. Say suppose i copy the code from unix to texpad/wordpad.Textpad will interpret tab as 8 spaces.(I can set... (4 Replies)
Discussion started by: pinnacle
4 Replies

5. Shell Programming and Scripting

Problem using egrep: spaces and newline

Hello: I am working in bash and am a newbie. I want to eliminate spaces from strings. Since this is a basic operation, I searched online and implemented the suggestions; however, I am facing a problem here. I have an input file which looks like this: abc defghi jklmno pqrs tuvw xyzabcd... (8 Replies)
Discussion started by: andyu11
8 Replies

6. UNIX for Dummies Questions & Answers

Problem with White spaces and tabs

Hi All, I am facing issues converting white spaces and tabs together in a file I am reading. Here is the command I am trying: tr -s ' '@ | sort -t@ +1n filename I guess the problem is that it is not converting the tabs to another delimiter. Also, I am supposed to accomplish this only using... (5 Replies)
Discussion started by: sh_kk
5 Replies

7. Web Development

[MYSQL] problem with spaces in rows

Hello. I'm not sure how I can get around this, or what I am doing wrong, but I need some help. :) I want to do an select query looking like this: SELECT venue, SUM( amount ) FROM IWD WHERE venue = 'Foxy Hollow' Unfortunately I need to have spaces in the names in these fields, is... (10 Replies)
Discussion started by: noratx
10 Replies

8. Shell Programming and Scripting

problem with spaces in filename

I have written a script to run ddrescue on a list of files. #!/bin/bash # # A script to rescue data recursively using ddrescue. srcDir=/damaged/hdd/movies/ #the source directory desDir=/new/hdd/movies/ #the destination directory... (2 Replies)
Discussion started by: colsinc
2 Replies

9. Shell Programming and Scripting

Problem with spaces in the path

Hi all, I have a variable test has the following value assigned.. could you please help on doing cd or ls to the value in the varible ... $echo $test /bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA\ Comments\ \&\ Responses $cd $test ksh: cd: bad argument count $cd... (3 Replies)
Discussion started by: firestar
3 Replies

10. Shell Programming and Scripting

"set variable with spaces and apostrophe after s"

Hi Guys, I have a variable such that: set x = (Session,Date,Type,Receive Coil Name,Manufacturer,Manufacturer's Model Name) foreach i ($x) echo $i end I would like to read each variable one by one like: Session Date Type Receive Coil Name Manufacturer Manufacturer's Model Name Is... (1 Reply)
Discussion started by: dixits
1 Replies
fields(3pm)						 Perl Programmers Reference Guide					       fields(3pm)

NAME
fields - compile-time class fields SYNOPSIS
{ package Foo; use fields qw(foo bar _Foo_private); sub new { my Foo $self = shift; unless (ref $self) { $self = fields::new($self); $self->{_Foo_private} = "this is Foo's secret"; } $self->{foo} = 10; $self->{bar} = 20; return $self; } } my Foo $var = Foo::->new; $var->{foo} = 42; # this will generate a compile-time error $var->{zap} = 42; # subclassing { package Bar; use base 'Foo'; use fields qw(baz _Bar_private); # not shared with Foo sub new { my $class = shift; my $self = fields::new($class); $self->SUPER::new(); # init base fields $self->{baz} = 10; # init own fields $self->{_Bar_private} = "this is Bar's secret"; return $self; } } DESCRIPTION
The "fields" pragma enables compile-time verified class fields. NOTE: The current implementation keeps the declared fields in the %FIELDS hash of the calling package, but this may change in future ver- sions. Do not update the %FIELDS hash directly, because it must be created at compile-time for it to be fully useful, as is done by this pragma. If a typed lexical variable holding a reference is used to access a hash element and a package with the same name as the type has declared class fields using this pragma, then the operation is turned into an array access at compile time. The related "base" pragma will combine fields from base classes and any fields declared using the "fields" pragma. This enables field inheritance to work properly. Field names that start with an underscore character are made private to the class and are not visible to subclasses. Inherited fields can be overridden but will generate a warning if used together with the "-w" switch. The effect of all this is that you can have objects with named fields which are as compact and as fast arrays to access. This only works as long as the objects are accessed through properly typed variables. If the objects are not typed, access is only checked at run time. The following functions are supported: new fields::new() creates and blesses a pseudo-hash comprised of the fields declared using the "fields" pragma into the specified class. This makes it possible to write a constructor like this: package Critter::Sounds; use fields qw(cat dog bird); sub new { my Critter::Sounds $self = shift; $self = fields::new($self) unless ref $self; $self->{cat} = 'meow'; # scalar element @$self{'dog','bird'} = ('bark','tweet'); # slice return $self; } phash fields::phash() can be used to create and initialize a plain (unblessed) pseudo-hash. This function should always be used instead of creating pseudo-hashes directly. If the first argument is a reference to an array, the pseudo-hash will be created with keys from that array. If a second argument is supplied, it must also be a reference to an array whose elements will be used as the values. If the second array contains less elements than the first, the trailing elements of the pseudo-hash will not be initialized. This makes it particularly useful for creating a pseudo-hash from subroutine arguments: sub dogtag { my $tag = fields::phash([qw(name rank ser_num)], [@_]); } fields::phash() also accepts a list of key-value pairs that will be used to construct the pseudo hash. Examples: my $tag = fields::phash(name => "Joe", rank => "captain", ser_num => 42); my $pseudohash = fields::phash(%args); SEE ALSO
base, "Pseudo-hashes: Using an array as a hash" in perlref perl v5.8.0 2002-06-01 fields(3pm)
All times are GMT -4. The time now is 05:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy