Sponsored Content
Full Discussion: Cut command skips spaces
Top Forums Shell Programming and Scripting Cut command skips spaces Post 302445572 by nimo on Monday 16th of August 2010 09:08:59 AM
Old 08-16-2010
Cut command skips spaces

Hi everyone

I have a file looks like this

Code:
 
X01 1   JOE      20100312
X02     TOD      20100312
X03   3 SAM      20100312

I wrote a script to assign the values in 5 columns to 5 variables. When I use cut command to assign column 2 or 3, it skips it if it is a space (see below)
Code:
while read LINE
   do
     VAR1=`echo $LINE | awk '{ print $1 }'`
     VAR2=`echo $LINE | cut -c 5`
     VAR3=`echo $LINE | cut -c 7`
     VAR4=`echo $LINE | awk '{ print $4 }'`
     VAR5=`echo $LINE | awk '{ print $5 }'`
     echo ${VAR1}"   "${VAR2}"   "${VAR3}"   "${VAR4}"   "${VAR5}
done < input_file

Could someone help please.

Moderator's Comments:
Mod Comment Use code tags please, ty.

Last edited by zaxxon; 08-16-2010 at 10:17 AM..
 

10 More Discussions You Might Find Interesting

1. HP-UX

Cron Skips Execution

Hi All, I got a very strange problem, i have created a cron schedule that will run a programme once in every 12 mins, like 04,16,28,40,52 * * * * /myf/startProcessA 1> &- Some time the cron skips the execution such as 04,28 instead of executing at 16 mins. it starts execution at 28, i... (6 Replies)
Discussion started by: nag_sundaram
6 Replies

2. Shell Programming and Scripting

no count of spaces in cut

i want to give numbers to cut without worrying about the spaces; echo "12 345 6 78 9" | cut -c 1-9 echo "123 456 789" | cut -c 1-9 echo "1 2 3 4 5 6 7 8 9" | cut -c 1-9 the output of these three must be allways; 123456789 is that posible? (6 Replies)
Discussion started by: Tártaro
6 Replies

3. UNIX for Dummies Questions & Answers

Removing Double Spaces for cut command

Hi I have a shell script that looks for running processes in order to kill them. The script (ksh) gets the PID of these processes using the following: PROCS=`ps -fu ${USERID} | egrep "MONITOR" | grep -v grep | cut -d" " -f4` However, I spotted an issue where PID's of different lengths... (3 Replies)
Discussion started by: mikem22
3 Replies

4. Shell Programming and Scripting

wget skips certain files.

I am trying to use wget to automate downloading of some mp3/wav files. However, I can't get it to follow the link to the mp3s. This is the line (it is not really the website): wget -prl 1 http://website.com/alarmsHowever, if I right-click and copy the link on the webpage in firefox, then... (4 Replies)
Discussion started by: Narnie
4 Replies

5. Shell Programming and Scripting

Include white spaces while using CUT command

Hi I tried to extract 19 characters (default) enclosed with in tag from a file using cut command. If the characters comprises of double space, the cut command gives the output with a single spacing. file 1 <name>Kumar Rajasekaran</name> cut -c7-26 "file1" the out put i received is ... (48 Replies)
Discussion started by: Sekar1
48 Replies

6. Shell Programming and Scripting

Remote script skips "read" command

This script is supposed to display a file ( crontab ), ask the user if they wish to update the file, then it goes through an update routine. #!/bin/bash FILE=/etc/crontab tail -5 $FILE echo -n "Does crontab need updating" read HOURS ...routines ....etc... Runs locally... (8 Replies)
Discussion started by: Bubnoff
8 Replies

7. UNIX for Dummies Questions & Answers

more f skips two pages

Hi, I am new to linux. I am using more command to view the contents of a file. If the file has many pages i am using f to move forward to the next page. But when i press f it skips to two pages instead of one page. i checked the man more. It shows the default is 1. Please share your... (1 Reply)
Discussion started by: nokiak810
1 Replies

8. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

9. UNIX for Dummies Questions & Answers

Cut pid from ps using cut command

hay i am trying to get JUST the PID from the ps command. my command line is: ps -ef | grep "mintty" | cut -d' ' -f2 but i get an empty line. i assume that the delimiter is not just one space character, but can't figure out what should i do in order to do that. i know i can use awk or cut... (8 Replies)
Discussion started by: ran ber
8 Replies

10. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 02:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy