12-20-2010
@asutoshch
When you have a Shell problem, please state what Operating System you are running and what Shell you are using.
If you have an expected output, please tell us what you expect as the output.
Anyway based on your code, this should work in most circumstances. Always put double quotes round string variables whether it is necessary or not.
LINE="AX80633030PHLIAD20209 1010104711411153 0054 000050000 11 PHLIAD1013112320100134-0003+003007000103+0033ER4ER4037012 N835HK0698D7 A2 A2E 05201011302010113020101130201011300000500000240000000TETE20101130NN8063201011300925IAD0004800045 5"
STR1=`echo "$LINE" | cut -c 86-88`
echo "$STR1"
003
Last edited by methyl; 12-20-2010 at 06:18 PM..
Reason: typos
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Let's say I have a line like that:
I want to cut out numbers between two $ including $s. The result should be like that:
I am so-newbei. I am non-stop reading about SED since yesterday and not a programmer. I know that it is a short period, thus maybe I had overlooked something. I... (4 Replies)
Discussion started by: l_p
4 Replies
2. Shell Programming and Scripting
Hi,
I have text file which contains lines like :
a/a/a/a/.project
b/b/b/b/b/.project
c/c/c/.project
d/.project
e/e/e/e/.project
i want for all lines the last word .project should be removed and the file should look like :
a/a/a/a/
b/b/b/b/b/
c/c/c/
....
how to proceed... (7 Replies)
Discussion started by: bhaskar_m
7 Replies
3. Shell Programming and Scripting
First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts.
Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea.
In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies
4. Shell Programming and Scripting
Hi All,
I would like help with a script which can get rid of the first work of all lines in text file.
File 1
The name is Scott.
Output : name is Scott
---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ----------
Hi ALL
There is typo error in... (3 Replies)
Discussion started by: bubbly
3 Replies
5. Shell Programming and Scripting
Hi I have some problem to cut out the second line in a output file and send to a new file it's a #!/bin/bash script
1 something
2 something
3 something
and after I cut
1 something
3 something
New file
2 something
Thanks in advance (7 Replies)
Discussion started by: pelle
7 Replies
6. Shell Programming and Scripting
Hi All,
I need to extract text 'ULTIMATE and 4spaces after it' from below line
77"2686"2010-11-21 14:09:13.000"4"I"200"1"2010-11-21 14:09:14.000"001:S087110131 ULTIMATE 4.99 T""
I have used cut command :
a=`echo $line | cut -f9 -d '"' | cut -c20-31`
echo $a
But... (5 Replies)
Discussion started by: angie1234
5 Replies
7. Shell Programming and Scripting
I am trying to grep the oracle erros evry day from the logs file. My problem is :
-rw-r----- 1 tibcolm tibco 17438361 Apr 5 11:59 RetryService-RetryService.log
-rw-r----- 1 tibcolm tibco 245303 Apr 5 12:00 ResponseService-ResponseService.log
-rw-r----- 1 tibcolm tibco 2122654 Apr 5 12:00... (4 Replies)
Discussion started by: neeraj617
4 Replies
8. Shell Programming and Scripting
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)
Discussion started by: Aditya_001
11 Replies
9. Shell Programming and Scripting
Need help to append a pipe at end of the line immediately after the cut command,
I have an Input flat file with 16 feilds and I am removing the 16th feild by using the cut command as shown,
Input:
354|||||CORPORTATION||||NENE PARADE|||WISBECH|CAMBRIDGESHIRE|PE13 3BY|100001|
I... (5 Replies)
Discussion started by: Aditya_001
5 Replies
10. Shell Programming and Scripting
Hi All,
I am facing an issue while cutting fields with comma delimiter. There are many records with Double quotes in between.
My data: aaa,bbb,"ccc, ddd",eee,fff,"ggg ,hhh",iii
When i use cut command with comma delimiter, i am getting wrong data like
field1=aaa
field2=bbb
field3="ccc... (3 Replies)
Discussion started by: krishna_gnv
3 Replies
cut(1) General Commands Manual cut(1)
NAME
cut - cut out (extract) selected fields of each line of a file
SYNOPSIS
list [file]...
list [file]...
list char] [file]...
DESCRIPTION
cuts out (extracts) columns from a table or fields from each line in a file; in data base parlance, it implements the projection of a rela-
tion. Fields as specified by list can be fixed length (defined in terms of character or byte position in a line when using the or option),
or the length can vary from line to line and be marked with a field delimiter character such as the tab character (when using the option).
can be used as a filter; if no files are given, the standard input is used.
When processing single-byte character sets, the and options are equivalent and produce identical results. When processing multi-byte char-
acter sets, when the and options are used together, their combined behavior is very similar, but not identical to the option.
Options
Options are interpreted as follows:
list A comma-separated list of integer byte option), character option), or field option) numbers, in increasing order,
with optional to indicate ranges. For example:
Positions 1, 4, and 7.
Positions 1 through 3 and 8.
Positions 1 through 5 and 10.
Position 3 through last position.
Cut based on a list of bytes.
Each selected byte is output unless the option is also specified.
Cut based on character positions specified by
list extracts the first 72 characters of each line).
Where list is a list of fields assumed to be separated in the file by a delimiter character (see for example, copies the
first and seventh field only. Lines with no field delimiters will be passed through intact (useful for table sub-
headings), unless is specified.
The character following
is the field delimiter option only). Default is tab. Space or other characters with special meaning to the shell
must be quoted. Adjacent field delimiters delimit null fields. char may be an international code set character.
Do not split characters.
If the high end of a range within a list is not the last byte of a character, that character is not included in the
output. However, if the low end of a range within a list is not the first byte of a character, the entire character
is included in the output."
Suppresses lines with no delimiter characters when using
option. Unless is specified, lines with no delimiters appear in the output without alteration.
Hints
Use to extract text from a file based on text pattern recognition (using regular expressions). Use to merge files line-by-line in columnar
format. To rearrange columns in a table in a different sequence, use and See grep(1) and paste(1) for more information.
EXTERNAL INFLUENCES
Environment Variables
determines the interpretation of text as single and/or multi-byte characters.
If is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty vari-
able. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization
variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5).
International Code Set Support
supports both single- and multi-byte character code sets. International code set characters may be specified in the char given to the
option. recognizes the international code set characters according to the locale specified in the environment variable.
EXAMPLES
Password file mapping of user ID to user names:
Set environment variable to current login name:
Convert file containing lines of arbitrary length into two files where contains the first 500 bytes (unless the 500th byte is within a
multi-byte character), and contains the remainder of each line:
DIAGNOSTICS
Line length must not exceed
characters or fields, including the new-line character (see limits(5).
Missing or option or incorrectly specified list. No error occurs if a line has fewer fields than the list calls for.
list is empty.
WARNINGS
does not expand tabs. Pipe text through expand(1) if tab expansion is required.
Backspace characters are treated the same as any other character. To eliminate backspace characters before processing by use the or com-
mand (see fold(1) and col(1)).
AUTHOR
was developed by OSF and HP.
SEE ALSO
grep(1), paste(1).
STANDARDS CONFORMANCE
cut(1)