Sponsored Content
Full Discussion: Problems with cut
Top Forums Shell Programming and Scripting Problems with cut Post 302189810 by era on Monday 28th of April 2008 02:33:52 AM
Old 04-28-2008
You need to properly quote your variables when you echo them, otherwise the shell will trim whitespace. I'd advise against using echo at all, though.

But here's how to quote properly. To be a little bit on the safe side, I also zap IFS; I don't believe it's strictly necessary here, but it's a technique you should be aware of.

Code:
OLDIFS=$IFS
IFS='
' # just a newline, in single quotes
while read data
do
  MSISDN="`echo "$data" | cut -c1-10`"
  HOUR="`echo "$data" | cut -c11-16`"
  ID_SA_SOURCE="`echo "$data" | cut -c17-35`"
  ID_SA_DEST="`echo "$data" | cut -c36-54`"
done < $TRACKING_LOGDIR/$listdata
IFS=$OLDIFS

Having that out of the way, how about something like this?

Code:
awk '{ OFS=":"; print substr($0, 1, 10), substr($0, 11, 16),
    substr($0, 17, 35), substr($0, 17, 35) }' $TRACKING_LOGDIR/$listdata |
while IFS=: read MSISDN HOUR ID_SA_SOURCE ID_SA_DEST; do
  echo "'$HOUR': All your '$ID_SA_SOURCE' are '$ID_SA_DEST' to '$MSISDN'"
done

 

3 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 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 07:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy