03-31-2006
Delete spaces in between fields- One Change
Here is my data
I have a file in the format below with about 15 fields per each record. I have 2 records displayed below.
"1234","Andy ","Rich ","0001","123 Main Street ","Dallas ", "1"
"2345","Andrew ","Richter ","0002","234 First Ave ","Kirby ", " "
My Final output needs to be as follows
"1234","Andy","Rich","0001","123 Main Street","Dallas","1"
"2345","Andrew","Richter","0002","234 First Ave","Kirby"," "
I am using the following Sed command and it works excep it also deletes the space in the field and I need the last data element to stay like it is either a "1" or a " " (space).
sed -e 's/[ ]"/"/g' inputfile>outputfile...
what do I need to change in the sed command that I am using to get the result that I am looking for. The above is just the sample of the data, and it is not all data elements, there are quite a few additional fields but the last field is what I have in my data sample.
Thanks
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi all...
i have the next question:
i have a flat file with a lot of records (lines). Each record has 10 fields, which are separated by pipe (|). My problem is what sometimes, in the first record, there are white spaces (no values, nothing) in the beginning of the record, like this:
ws ws... (2 Replies)
Discussion started by: DebianJ
2 Replies
2. Shell Programming and Scripting
hi all,
i have a big problem, and i donīt know what to do.
i have a flat file with several fields, which are separated by ";" like this:
5656838-7B;97030000-7;*;V16106133 ;1;1;
4612062-0B;97030000-7;*;C14038149 ;1;2;
8044938-0B;97030000-7;*;V16034219 ;1;2;
where B is a blank space.
... (2 Replies)
Discussion started by: DebianJ
2 Replies
3. Shell Programming and Scripting
Hey ,
I have a file and it's having spaces for some of the fields in it. Like the one below. I want to remove the spaces in them through out the file. The spaces occur randomly and i can't say which field is having space. So please help. Here is sample file with spaces after 5th field. (3 Replies)
Discussion started by: dsravan
3 Replies
4. UNIX for Dummies Questions & Answers
This is what I need to do
I have a file that has a field with values like this
1111 2222
3333 4444
55555 666
333333333
444444444
I need for my command to out put only those fields that do not have spaces in them. So my output for the above file would be
333333333
444444444
how... (10 Replies)
Discussion started by: alfredo123
10 Replies
5. Shell Programming and Scripting
Hi,
I have a source file as mentioned below: I want to remove all the extra spaces between the fields.
a b--------|sa df-------|3232---|3
sf sa------|afs sdf-----|43-----|33
a b c------|adfsa dsf---|23-32|23
*Here '-' idicates spaces
Now, I want output as below:
a b|sa df|3232|3... (7 Replies)
Discussion started by: srilaxmi
7 Replies
6. Shell Programming and Scripting
Hi Friends,
I have large volume of data file as shown below.
Beganing or end of each filed, there are some blank spaces.
How do I remove those spaces?
AAA AAA1 | BBB BB1 BB2 |CC CCCC
DDDD DD | EEEEEEE EEEEEEEE | FFF FFFFFF FFFF
GG GGGGGG |HH HH ... (3 Replies)
Discussion started by: ppat7046
3 Replies
7. Shell Programming and Scripting
Hi,
Does any one know how to avoid the scenario where awk ignores the fields having only spaces or empty fields?
for instance,
Data: "a","b","c","d",""," "
code:
awk -F, '{ print NF }' File
the output I get is 4 instead of 6 do you know how to avoid this? (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies
8. Shell Programming and Scripting
SHELL SCRIPT
Hi
I have a file in the following format
Mayank Sushant
Dheeraj Kunal
ARUN Samir
How can i replace the white space in between and replace them with a comma?? The resultant output should be
Mayank,Sushant
Dheeraj,Kunal
ARUN,Samir
i tried using
sed -e... (8 Replies)
Discussion started by: mayanksargoch
8 Replies
9. Shell Programming and Scripting
Please see the following code, between "status" and "OK" exists many spaces, I want to get status OK . how to ignore multi spaces? If tab exists in the spaces, how to ignore it ?
Is there other commands can replace cut?
$ echo 'drv status OK'| cut... (3 Replies)
Discussion started by: 915086731
3 Replies
10. Shell Programming and Scripting
I'm trying to do something pretty simple but its appears more complicated than expected... I've lines in a text file, separated by the comma and that I want to output to another file, without the first field.
Input file:
file1,item, 12345678
file2,item, 12345678
file2,item, ... (8 Replies)
Discussion started by: Armoric
8 Replies
LEARN ABOUT REDHAT
strfmon
STRFMON(3) Linux Programmer's Manual STRFMON(3)
NAME
strfmon - convert monetary value to a string
SYNOPSIS
#include <monetary.h>
ssize_t strfmon(char *s, size_t max, const char *format,
...);
DESCRIPTION
The strfmon() function formats the specified amounts according to the format specification format and places the result in the character
array s of size max.
Ordinary characters in format are copied to s without conversion. Conversion specifiers are introduced by a `%' character. Immediately
following it there can be zero or more of the following flags:
=f The single-byte character f is used as the numeric fill character (to be used with a left precision, see below). When not speci-
fied, the space character is used.
^ Do not use any grouping characters that might be defined for the current locale. By default, grouping is enabled.
( or + The ( flag indicates that negative amounts should be enclosed between parentheses. The + flag indicates that signs should be handled
in the default way, that is, amounts are preceded by the locale's sign indication, e.g., nothing for positive, "-" for negative.
! Omit the currency symbol.
- Left justify all fields. The default is right justification.
Next, there may be a field width: a decimal digit string specifying a minimum field width in bytes. The default is 0. A result smaller
than this width is padded with spaces (on the left, unless the left-justify flag was given).
Next, there may be a left precision of the form "#" followed by a decimal digit string. If the number of digits left of the radix character
is smaller than this, the representation is padded on the left with the numeric fill character. Grouping characters are not counted in
this field width.
Next, there may be a right precision of the form "." followed by a decimal digit string. The amount being formatted is rounded to the spec-
ified number of digits prior to formatting. The default is specified in the frac_digits and int_frac_digits items of the current locale.
If the right precision is 0, no radix character is printed. (The radix character here is determined by LC_MONETARY, and may differ from
that specified by LC_NUMERIC.)
Finally, the conversion specification must be ended with a conversion character. The three conversion characters are
% (In this case the entire specification must be exactly "%%".) Put a `%' character in the result string.
i One argument of type double is converted using the locale's international currency format.
n One argument of type double is converted using the locale's national currency format.
RETURN VALUE
The strfmon() function returns the number of characters placed in the array s, not including the terminating NUL character, provided the
string, including the terminating NUL, fits. Otherwise, it sets errno to E2BIG, returns -1, and the contents of the array is undefined.
EXAMPLE
The call
strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
1234.567, 1234.567);
outputs
[ fl **1234,57] [ NLG **1 234,57]
in the Dutch locale (with fl for "florijnen" and NLG for Netherlands Guilders). The grouping character is very ugly because it takes as
much space as a digit, while it should not take more than half that, and will no doubt cause confusion. Surprisingly, the "fl" is preceded
and followed by a space, and "NLG" is preceded by one and followed by two spaces. This may be a bug in the locale files. The Italian, Aus-
tralian, Swiss and Portuguese locales yield
[ L. **1235] [ ITL **1.235]
[ $**1234.57] [ AUD **1,234.57]
[Fr. **1234,57] [CHF **1.234,57]
[ **1234$57Esc] [ **1.234$57PTE ]
SEE ALSO
setlocale(3), sprintf(3), locale(7)
Linux 2000-12-05 STRFMON(3)