11-10-2008
Remove spaces from first field, and write entire contents into other text file
Hi all,
I have searched and found various threads about removing spaces from a field within a text file. Unfortunately, I have not found exactly what I'm looking for, nor am I adept enough to modify what I've found into what I need.
I use the following command to remove the first line from a text file (the column headers): sed 1d file > file2
I then want to strip the leading spaces from the first field only, but so far, all I can do is the following: cat file2 | awk '{print $1}' > file3
That successfully strips the spaces, but only gives me that one field. Since the number of fields could vary from day to day (an updated field is received every night, and additional fields are often added), how can I modify that script to ensure all fields are written to the new file with the spaces stripped only from the first field?
Thank you,
Carrie
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I need to remove the entire file contents in file using the shell script.
Actually the grap -v command will create one more file and it occupy the space also.
I need to remove the entire file contents without creating new file using the shell scripting.
Please help me. (5 Replies)
Discussion started by: praka
5 Replies
2. Shell Programming and Scripting
Hi,
I have this problem that there are blank spaces in my text file... i want to remove them
line 1
line 2
line 3
I want to remove the space between line 2 and line 3... I tried sed... it work but it prints the whole text file at the command prompt which i dont want....
sde i tried was... (4 Replies)
Discussion started by: bhagya2340
4 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I am trying to figure out how to copy the contents of a file to the clipboard, then paste into a command. i.e copy contents of file /path/filename.txt to <command> <paste text>
Hope that makes sense. Basically tryting to copy the text for use in a command without having to open the... (8 Replies)
Discussion started by: JCA70
8 Replies
4. Shell Programming and Scripting
Hi
I have a data file 'File2' consisting of 105670 lines. I want to copy and paste 17928 lines from 'File1' to 'File2' but I want to place it in between lines 21 and 17950 of 'File2'. How do I do it in awk?
For example-
File A has 5 lines
X
Y
1 2 3
4 5 6
7 8 9
and File B has
A
b... (1 Reply)
Discussion started by: ananyob
1 Replies
5. Shell Programming and Scripting
Hi
I have a data file 'File2' consisting of 105670 lines. I want to copy and paste 17928 lines from 'File1' to 'File2' but I want to place it in between lines 21 and 17950 of 'File2'. How do I do it in awk?
For example-
File A has 5 lines
X
Y
1 2 3
4 5 6
7 8 9
and File B has
A
b... (1 Reply)
Discussion started by: ananyob
1 Replies
6. Shell Programming and Scripting
Hi all,
Is there a sed/awk cmd that will remove blank space from between words in a particular field, replacing with a single space?
Field containing 'E's in the example below:
Example input file:
AAAAA AA|BBBB|CCCCCCC|DDDDDD |EEEE EEEEEE| FFF FFFFF|
... (6 Replies)
Discussion started by: dendright
6 Replies
7. Shell Programming and Scripting
Hi,
I have a huge file that has data something like shown below:
huge_file.txt
start regexp
Name=Name1
Title=Analyst
Address=Address1
Department=Finance
end regexp
some text
some text
start regexp
Name=Name2
Title=Controller
Address=Address2
Department=Finance
end regexp (7 Replies)
Discussion started by: r3d3
7 Replies
8. Shell Programming and Scripting
Hi all,
I want to remove empty field in a text file. I tried to used sed. But it failed.
Input:
LG10_PM_map_19_LEnd 1000560 G AG AG
LG10_PM_map_19_LEnd 1005621 G AG
LG10_PM_map_19_LEnd 1011214 A AG AG
LG10_PM_map_19_LEnd 1011673 T CT CT ... (3 Replies)
Discussion started by: huiyee1
3 Replies
9. Shell Programming and Scripting
Greetings.
I've got a csv file with data along these lines:
Spumoni's Pizza Place, Placemats n Things, Just Lamps
Counterfeit Dollars by Vinnie, Just Shades, Dollar StoreI want to replace the entire comma-delimited field if it matches something ending in "Place" or beginning with "Dollar",... (2 Replies)
Discussion started by: palmfrond
2 Replies
10. UNIX for Beginners Questions & Answers
Hi,
At the moment, using Notepad++ to do a search and replace, manually section by section which is real painful. Yeah, so copying each section of the line of text and putting into a file and then search and replace, need at least 3-operations in Notepad++.
Here's hoping I will be able to... (1 Reply)
Discussion started by: newbie_01
1 Replies
LEARN ABOUT SUSE
field_buffer
field_buffer(3FORM) field_buffer(3FORM)
NAME
field_buffer - field buffer control
SYNOPSIS
#include <form.h>
int set_field_buffer(FIELD *field, int buf, const char *value);
char *field_buffer(const FIELD *field, int buffer);
int set_field_status(FIELD *field, bool status);
bool field_status(const FIELD *field);
int set_max_field(FIELD *field, int max);
DESCRIPTION
The function set_field_buffer sets the numbered buffer of the given field to contain a given string:
- Buffer 0 is the displayed value of the field.
- Other numbered buffers may be allocated by applications through the nbuf argument of (see field_new(3FORM)) but are not manipulated
by the forms library.
The function field_buffer returns a pointer to the contents of the given numbered buffer:
- The buffer contents always have the same length, and are padded with trailing spaces as needed to ensure this length is the same.
- The buffer may contain leading spaces, depending on how it was set.
- The buffer contents are set with set_field_buffer, or as a side effect of any editing operations on the corresponding field.
- Editing operations are based on the window which displays the field, rather than a string. The window contains only printable char-
acters, and is filled with blanks. If you want the raw data, you must write your own routine that copies the value out of the buffer
and removes the leading and trailing spaces.
- Because editing operations change the content of the buffer to correspond to the window, you should not rely on using buffers for
long-term storage of form data.
The function set_field_status sets the associated status flag of field; field_status gets the current value. The status flag is set to a
nonzero value whenever the field changes.
The function set_max_field sets the maximum size for a dynamic field. An argument of 0 turns off any maximum size threshold for that
field.
RETURN VALUE
The field_buffer function returns NULL on error. It sets errno according to their success:
E_OK The routine succeeded.
E_BAD_ARGUMENT
Routine detected an incorrect or out-of-range argument.
The field_status function returns TRUE or FALSE.
The remaining routines return one of the following:
E_OK The routine succeeded.
E_SYSTEM_ERROR
System error occurred (see errno).
E_BAD_ARGUMENT
Routine detected an incorrect or out-of-range argument.
SEE ALSO
ncurses(3NCURSES) and related pages whose names begin "form_" for detailed descriptions of the entry points.
NOTES
The header file <form.h> automatically includes the header file
When configured for wide-characters, field_buffer returns a pointer to temporary storage (allocated and freed by the library). The appli-
cation should not attempt to modify the data. It will be freed on the next call to field_buffer to return the same buffer. <curses.h>.
PORTABILITY
These routines emulate the System V forms library. They were not supported on Version 7 or BSD versions.
AUTHORS
Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S. Raymond.
field_buffer(3FORM)