Removing spaces at particular position


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing spaces at particular position
# 8  
Old 07-10-2006
With awk :
Code:
awk -v FS=~ -v OFS=~ '
{
   gsub(/ /,"",$4);
   gsub(/ /,"",$5);
   gsub(/ /,"",$6);
   gsub(/ /,"",$7);
   gsub(/ /,"",$8);
   print;
} ' input_file > output_file


If you want to remove only trailing spaces, change the gsub statements like this :
Code:
sub(/ *$/,"",$4);


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I replace a string in file that is in a certain position with spaces?

I am trying to replace the string in position 26 through 35 of the data file with 10 spaces and I want the remaining file to stay as is, the record length is over 900 characters? I am trying to use the AWK and substr but I am not getting it formatted correctly. Before... (6 Replies)
Discussion started by: fnwine1500
6 Replies

2. Linux

Removing a character at specific position in a column

Hi, I have a file like this (about 8 columns in total, this being the 2nd column) gi_49482297_ref_YP_039521.1_ gi_49482297_ref_YP_039521.1_ gi_49482315_ref_YP_039539.1_ gi_49482315_ref_YP_039539.1_I want to remove the _ at the end of the line. And at later stages I would want to replace the... (5 Replies)
Discussion started by: Syeda Sumayya
5 Replies

3. Shell Programming and Scripting

Removing blanks, spaces

I have pipe separated file with lots of blank spaces. After using sed -e 's/ *| */|/g' this command ,its giving me output as TT0000013101640| HCAMBLAMCNB010|Jul 3 2012 11:14AM| HARYANA| Bangali Mohalla | TCL-UBR|9368040005|9355264655|9218509220|NULL ... (5 Replies)
Discussion started by: sususa
5 Replies

4. Shell Programming and Scripting

Remove the spaces at the end of a line starting from a fixed position

I want to remove the trailing spaces at the end of each line starting from a particular position(using ksh script). For example, in the attached file, I want to remove all the spaces starting from the position 430 till the end. The space has to be removed only from the 430th position no matter in... (3 Replies)
Discussion started by: Suryaaravindh
3 Replies

5. Shell Programming and Scripting

Removing 0 from a specific position - if it exists

I have a file that I need to parse using a script. The dates in the file are displayed in the format: Mar 2, 2011 9:09:31 PM I have tried using the date command %e and %l but it pads an extra space for the day and hour if they are single digits. So this I used a normal date command: ... (6 Replies)
Discussion started by: crazyideas
6 Replies

6. Shell Programming and Scripting

using awk removing newline and specific position

Hello Friends, Input File looks as follows: >FASTA Header1 line1 line2 line3 linen >FASTA Header2 Line1 Line2 linen >FASTA Header3 and so on ....... Output: Want something as: >FASTA Header1 line1line2line3linen >FASTA Header2 (5 Replies)
Discussion started by: Deep9000
5 Replies

7. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

8. UNIX for Dummies Questions & Answers

Removing spaces...

Hey, I'm using the command from this thread https://www.unix.com/unix-dummies-questions-answers/590-converting-list-into-line.html to convert vertical lines to horzontal lines. But I need to remove the spaces that is created. Unfortunately I can't figure out where the space is in the code.. I... (2 Replies)
Discussion started by: lost
2 Replies

9. Shell Programming and Scripting

removing spaces

hey.. i had a problem with the unix command when i want to remove the white spaces in a string..i guess i cud do it with a sed command but i get an error when i give space in the square brackets.. string="nh hjh llk" p=`echo $string | sed 's/ //g'` i donno how to give space charater and... (2 Replies)
Discussion started by: sahithi_khushi
2 Replies

10. UNIX for Dummies Questions & Answers

removing spaces from variables?

I stored results like this VAR=`wc -l < ls.txt` But the value of the wc gave me a padded number. How do I strip the padding from $VAR? Do you think I could use SED? Except instead of a file input, have a variable redirection input? (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question
X2SYS_DATALIST(1gmt)					       Generic Mapping Tools					      X2SYS_DATALIST(1gmt)

NAME
x2sys_datalist - A generic data-extractor for ASCII or binary files SYNOPSIS
x2sys_datalist track(s) -TTAG [ -A ] [ -Fname1,name2,... ] [ -H[i][nrec] ] [ -L[corrtable] ] [ -Rwest/east/south/north[r] ] [ -S ] [ -V ] [ -bo[s|S|d|D[ncol]|c[var1/...]] ] [ -m[flag] ] DESCRIPTION
x2sys_datalist reads one or more files and produces a single ASCII [or binary] table. The files can be of any format, which must be described and passed with the -T option. You may limit the output to a geographic region, and insist that the output from several files be separated by a multiple segment header. Only the named data fields will be output [Default selects all columns]. tracks Can be one or more ASCII, native binary, or COARDS netCDF 1-D data files. To supply the data files via a text file with a list of tracks (one per record), specify the name of the track list after a leading equal-sign (e.g., =tracks.lis). If the names are miss- ing their file extension we will append the suffix specified for this TAG. Track files will be searched for first in the current directory and second in all directories listed in $X2SYS_HOME/TAG/TAG_paths.txt (if it exists). [If $X2SYS_HOME is not set it will default to $GMT_SHAREDIR/x2sys]. (Note: MGD77 files will also be looked for via MGD77_HOME/mgd77_paths.txt and *.gmt files will be searched for via $GMT_SHAREDIR/mgg/gmtfile_paths). -T Specify the x2sys TAG which tracks the attributes of this data type. OPTIONS
No space between the option flag and the associated arguments. -A Eliminate COEs by distributing the COE between the two tracks in proportion to track weight. These (dist, adjustment) spline knots files for each track and data column are called track.column.adj and are expected to be in the $X2SYS_HOME/TAG directory. The adjustments are only applied if the corresponding adjust file can be found [No residual adjustments] -F Give a comma-separated sub-set list of column names defined in the definition file. [Default selects all data columns]. -H Input file(s) has header record(s). If used, the default number of header records is N_HEADER_RECS. Use -Hi if only input data should have header records [Default will write out header records if the input data have them]. Blank lines and lines starting with # are always skipped. -L Apply optimal corrections to columns where such corrections are available. Append the correction table to use [Default uses the correction table TAG_corrections.txt which is expected to reside in the $X2SYS_HOME/TAG directory]. For the format of this file, see CORRECTIONS below. -R west, east, south, and north specify the Region of interest, and you may specify them in decimal degrees or in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Append r if lower left and upper right map coordinates are given instead of w/e/s/n. The two shorthands -Rg and -Rd stand for global domain (0/360 and -180/+180 in longitude respectively, with -90/+90 in latitude). Alterna- tively, specify the name of an existing grid file and the -R settings (and grid spacing, if applicable) are copied from the grid. For Cartesian data just give xmin/xmax/ymin/ymax. This option limits the COEs to those that fall inside the specified domain. -S Suppress output records where all the data columns are NaN [Default will output all records]. -V Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. -bo Selects binary output. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Option- ally, append ncol, the number of desired columns in your binary output file. -m Output a multisegment header between data from each track. Note this option does not imply anything about the input file; that information is conveyed via the system tag (-T). EXAMPLES
To extract all data from the old-style MGG supplement file c2104.gmt, recognized by the tag GMT: x2sys_datalist c2104.gmt -TGMT > myfile To make lon,lat, and depth input for blockmean and surface using all the files listed in the file tracks.lis and define by the tag TRK, but only the data that are inside the specified area, and make output binary, run x2sys_datalist =tracks.lis -TTRK -Flon,lat,depth -R-40/-30/25/35 -bo > alltopo_bin.xyz CORRECTIONS
The correction table is an ASCII file with coefficients and parameters needed to carry out corrections. This table is usually produced by x2sys_solve. Comment records beginning with # are allowed. All correction records are of the form trackID observation correction where trackID is the track name, observation is one of the abbreviations for an observed field contained in files under this TAG, and cor- rection consists of one or more white-space-separated terms that will be subtracted from the observation before output. Each term must have this exact syntax: factor[*[function]([scale](abbrev[-origin]))[^power]] where terms in brackets are optional (the brackets themselves are not used but regular parentheses must be used exactly as indicated). No spaces are allowed except between terms. The factor is the amplitude of the basis function, while the optional function can be one of sin, cos, or exp. The optional scale and origin can be used to translate the argument (before giving it to the optional function). The argument abbrev is one of the abbreviations for columns known to this TAG. However, it can also be one of the three auxiliary terms dist (for along-track distances), azim for along-track azimuths, and vel (for along-track speed); these are all sensitive to the -C and -N settings used when defining the TAB; furthermore, vel requires time to be present in the data. If origin is given as T it means that we should replace it with the value of abbrev for the very first record in the file (this is usually only done for time). If the first data record entry is NaN we revert origin to zero. Optionally, raise the entire expression to the given power, before multiplying by factor. The fol- lowing is an example of fictitious corrections to the track ABC, implying the z column should have a linear trend removed, the field obs should be corrected by a strange dependency on latitude, weight needs to have 1 added (hence correction is given as -1), and fuel should be reduced by a linear distance term: ABC z 7.1 1e-4*((time-T)) ABC obs 0.5*exp(-1e-3(lat))^1.5 ABC weight -1 ABC fuel 0.02*((dist)) SEE ALSO
blockmean(1), GMT(1), surface(1), x2sys_init(1), x2sys_datalist(1), x2sys_get(1), x2sys_list(1), x2sys_put(1), x2sys_report(1), x2sys_solve(1) GMT 4.5.7 15 Jul 2011 X2SYS_DATALIST(1gmt)