I'm new to shell programming, and am having a problem in a (Korn) shell program, which boils down to this:
The program reads a record from an input file and then uses a series of
"cut" commands to break the record into parts and assign the parts to
variables. There are no delimiters in the record. Here's a sequence of
three records from the input file:
S1830031HN106P S1830032HN113XTA S1830033MEI A
And here's the section of code that breaks the record into various parts,
with "InputLine" representing the record:
So the code should assign the characters in columns 9-13 to the var5
variable. The problem is that when the third record above ("S1830033MEI
A") is processed, the var5 should be assigned "MEI ", but ends up getting
assigned "MEI A". In the record, there are four spaces between the "I" and the "A", but the cut command seems to compress the consecutive whitespaces into one space, which then makes the "A" the fifth character in the variable. Is there a way to force the cut command to count each whitespace as a column, or some other simple way to assign exactly those characters in columns 9-13 to var5? I tried using various options with the cut command, but wasn't able to get the results I needed. I appreciate any help anyone can give.
Hi all!
Here is my problem :
$ more file
yougli:passwd:123456:3265:Yepa Yepo:/home/yougli:/bin/ksh
As you can see, in the field "information", there are two spaces between "Yepa" and "yepo".
My problem is :
$ PARAM='more file | cut -d":" -f5'
$ echo $PARAM
Yepa Yepo
Now i only... (2 Replies)
I am trying to take one part of my text from file and save it to variable $x
I tryed this...
x=`cut -c 6-9 $fajl`
my file looks like this
fajl:
21890001277 89386911 23638FBCDC 28EE01A1 0000 26855 124 244326
21890001277 89766911 23638FBCDC 28E021A1 0000 26557 134 684326
21890001277... (7 Replies)
Guys,
I've a problem in the "sed" command used in my shellscripts
This is the problamatic line in my shell script:
sed -e 's/${line1}/${line1_m}/g' prod_hier_1234.txt > test.txt
It doesn't do the job of replacing the string stored in variable 'line1' to 'line1_m'.
However If I replace the... (10 Replies)
Hi Guru's,
I 'm trying to execute the below given script in Unix. I am having an issue with the script. The output of the script is given below:
#!/bin/bash
File_Home="/home/essftp/Risk"
cd /home/essftp/Risk
rm -f FileList
rm -f credit_risk*
file1=`ls -lt... (4 Replies)
Hi
I have a strange problem when using cut command
when i am using the below command, it is working fine,I am getting the data in new file xyz.dat
cut -c 1-75 abc.dat > xyz.dat
when i am using the below command, I am getting the data in new file abc.dat , but empty file
cut -c 1-75... (4 Replies)
Hi!
I get a md5 hash of a file with this command:
openssl md5 /Users/me/MyLogo.png | cut -f 2 -d ' '
"cut" because I just want the hash. But there is a problem -> that doen't work with a path with spaces:
openssl md5 /Users/me/MyLogo 2.png | cut -f 2 -d ' '
The result is "2.png)=" ...... (1 Reply)
Hi,
I have used expr command to increment the date.
for e.g.,
case 1 :
echo $(date -d $(echo `expr 20010101 + 1`))
it returns
Tue Jan 2 00:00:00 IST 2001
case 2:
echo $(date -d $(echo `expr 20010101 - 1`))
it returns
date: invalid date `20010100'
please suggest me, how to... (3 Replies)
I am writing a shell script to skip couple of feilds in a flat file and as a part of this I have written the below piece of code in it.
cut -d '|' -f 1-17,19-31 $1 > filename
To add pipe at end of the line I used below command, but it adds even to header and footer as well which i... (11 Replies)
Hi Friend ,
i have one file say xyz.lst and it has content like
dn: cn=m.hariharan,cn=employee,cn=delhi circle,cn=users,dc=industowers,dc=c
dn: cn=ajay.jain,cn=employee,cn=gujarat circle,cn=users,dc=industowers,dc=com
dn: cn=ajitkumar.thakor,cn=employee,cn=gujarat... (4 Replies)
There is a text file in my project named as "mom.txt" in which i want to have contents like..................
LSCRM(Application Name):
1: This is my first application.
2: Today we did shell scripting automation for this app.
3: It was really a good fun in doing so.
4: Really good.| (Here i... (7 Replies)
Discussion started by: Abhijeet Anand
7 Replies
LEARN ABOUT CENTOS
cut
CUT(1) User Commands CUT(1)NAME
cut - remove sections from each line of files
SYNOPSIS
cut OPTION... [FILE]...
DESCRIPTION
Print selected parts of lines from each FILE to standard output.
Mandatory arguments to long options are mandatory for short options too.
-b, --bytes=LIST
select only these bytes
-c, --characters=LIST
select only these characters
-d, --delimiter=DELIM
use DELIM instead of TAB for field delimiter
-f, --fields=LIST
select only these fields; also print any line that contains no delimiter character, unless the -s option is specified
-n with -b: don't split multibyte characters
--complement
complement the set of selected bytes, characters or fields
-s, --only-delimited
do not print lines not containing delimiters
--output-delimiter=STRING
use STRING as the output delimiter the default is to use the input delimiter
--help display this help and exit
--version
output version information and exit
Use one, and only one of -b, -c or -f. Each LIST is made up of one range, or many ranges separated by commas. Selected input is written
in the same order that it is read, and is written exactly once. Each range is one of:
N N'th byte, character or field, counted from 1
N- from N'th byte, character or field, to end of line
N-M from N'th to M'th (included) byte, character or field
-M from first to M'th (included) byte, character or field
With no FILE, or when FILE is -, read standard input.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report cut translation bugs to <http://translationproject.org/team/>
AUTHOR
Written by David M. Ihnat, David MacKenzie, and Jim Meyering.
COPYRIGHT
Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
The full documentation for cut is maintained as a Texinfo manual. If the info and cut programs are properly installed at your site, the
command
info coreutils 'cut invocation'
should give you access to the complete manual.
GNU coreutils 8.22 June 2014 CUT(1)