05-12-2008
stripping certain characters in at the middle of a string
I am trying to strip out certain characters from a string on both (left & right) sides. For example, line=see@hear|touch, i only want to echo the "hear" part. Well i have tried this approach:
line=see@hear|touch
templine=${line#*@} #removed "see@"
echo ${templine%%\|*} #removed "|touch"
hear
...apparently it worked but i want to do this in only one line. Can anyone suggest a way on how to do this?
Another question, what if i added some more characters like this:
line=see@hear|touch|smell
...now i wanted to separate each and every one of them dynamically* like this: (*the values for templine2, 3 & 4 may vary)
templine1=see
templine2=hear
templine3=touch
templine4=smell
...can anyone also suggest on this one?
Many thanks
10 More Discussions You Might Find Interesting
1. Programming
I have a problem that I want to insert and delete some chars in the middle of a file. fopen() and fdopen() just allow to append at the end.
Is there any simple method or existing library that allow these actions? Thanks in advance.:confused: (7 Replies)
Discussion started by: ivancheung
7 Replies
2. UNIX for Dummies Questions & Answers
Hi,
How to strip a portion of a file name from behind...Say for Eg..i have a file name like aaaaa.bbbbb.Mar-17-2007
i want to remove .Mar-17-2007...is there a one line command which can give this output...
Thanks
Kumar (5 Replies)
Discussion started by: kumarsaravana_s
5 Replies
3. Shell Programming and Scripting
Hi there, if i have some strings ie
test_324423
test_242332
test_767667
but I only want the number part (the bolded bit) how do I strip the leftmost 5 characters from the output so that i will have just
324423
242332
767667
any help would be greatly appreciated
Gary (5 Replies)
Discussion started by: hcclnoodles
5 Replies
4. Shell Programming and Scripting
Hi ,
i have to strip the spaces in the string which has the following value
ABC DEF
i want this to appear like this
ABC DEF
is there any spilt method?
please help....
Thanks (3 Replies)
Discussion started by: rag84dec
3 Replies
5. Shell Programming and Scripting
I want to create a temp file which is named based on a search string. The search string may contain spaces or characters that aren't supposed to be used in filenames so I want to strip those out.
My thought was to use 'tr' with but the result is the opposite of what I want:
$ echo "test... (5 Replies)
Discussion started by: mglenney
5 Replies
6. UNIX for Dummies Questions & Answers
I tried to replace the following in vi:
old: 'e/thesis/pp/zones/zones'
new: 'd/so162/fix/pp'
For that, I used: :%s/e/thesis/pp/zones/zones/d/so162/fix/pp/g
but doesn't work, a trailing character error message appeared. How can I get it?
Thanks in advance (3 Replies)
Discussion started by: Gery
3 Replies
7. Shell Programming and Scripting
I'm using a shell script to get user input with this command:
read UserInput
I would then like to take the "UserInput" variable and strip out all of the following characters, regardless of where they appear in the variable or how many occurrences there are:
\/":|<>+=;,?*@
I'm not sure... (5 Replies)
Discussion started by: nrogers64
5 Replies
8. Shell Programming and Scripting
i want to parse a string and only display the digits in that string... How would i accomplish this with sed command.
For example.
input string: " 033434343 dafasdf"
output string: 03343434
Thanks (2 Replies)
Discussion started by: timmylita
2 Replies
9. Shell Programming and Scripting
Dear experts,
my problem is pretty tricky.
I want to change a file (see attached input.txt), according to another file (help.txt). The output that is desired is in output.txt. The example is attached.
Note that
-dashes should not be treated specially, they are considered normal characters,... (2 Replies)
Discussion started by: TheTransporter
2 Replies
10. Shell Programming and Scripting
I wrote myself a small little shell script to clean up a file I have issues with. In particular, I am stripping down a fully qualified host/domain name to just the hostname itself. The script works, but from a performance standpoint, it's not very fast and I will be working with large data sets.
... (4 Replies)
Discussion started by: dagamier
4 Replies
LEARN ABOUT SUSE
is_linetouched
touch(3NCURSES) touch(3NCURSES)
NAME
touchwin, touchline, untouchwin, wtouchln, is_linetouched, is_wintouched - curses refresh control routines
SYNOPSIS
#include <curses.h>
int touchwin(WINDOW *win);
int touchline(WINDOW *win, int start, int count);
int untouchwin(WINDOW *win);
int wtouchln(WINDOW *win, int y, int n, int changed);
bool is_linetouched(WINDOW *win, int line);
bool is_wintouched(WINDOW *win);
DESCRIPTION
The touchwin and touchline routines throw away all optimization information about which parts of the window have been touched, by pretend-
ing that the entire window has been drawn on. This is sometimes necessary when using overlapping windows, since a change to one window af-
fects the other window, but the records of which lines have been changed in the other window do not reflect the change. The routine touch-
line only pretends that count lines have been changed, beginning with line start.
The untouchwin routine marks all lines in the window as unchanged since the last call to wrefresh.
The wtouchln routine makes n lines in the window, starting at line y, look as if they have (changed=1) or have not (changed=0) been changed
since the last call to wrefresh.
The is_linetouched and is_wintouched routines return TRUE if the specified line/window was modified since the last call to wrefresh; other-
wise they return FALSE. In addition, is_linetouched returns ERR if line is not valid for the given window.
RETURN VALUE
All routines return the integer ERR upon failure and an integer value other than ERR upon successful completion, unless otherwise noted in
the preceding routine descriptions.
X/Open does not define any error conditions. In this implementation
is_linetouched
returns an error if the window pointer is null, or if the line number is outside the window. Note that ERR is distinct from
TRUE and FALSE, which are the normal return values of this function.
wtouchln
returns an error if the window pointer is null, or if the line number is outside the window.
PORTABILITY
The XSI Curses standard, Issue 4 describes these functions.
Some historic curses implementations had, as an undocumented feature, the ability to do the equivalent of clearok(..., 1) by saying touch-
win(stdscr) or clear(stdscr). This will not work under ncurses.
NOTES
Note that all routines except wtouchln may be macros.
SEE ALSO
ncurses(3NCURSES), refresh(3NCURSES).
touch(3NCURSES)