ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to extract only values after jsp?id= for example from 'jsp?id=1600809955' I want to extract 1600809955 and print it, if any duplicate entry remove while printing
I want to extract only values after jsp?id= for example from 'jsp?id=1600809955' I want to extract 1600809955 and print it, if any duplicate entry remove while printing
...since you asked about extracting strings three years ago. And that thread contains links to several OTHER of your posts over the years, asking for scripts and similar things. Can't you apply what you've been told many times previously, and make it work for you?
You've been here FOURTEEN YEARS now, so you should be well familiar (especially since you've been told many times) with the "Question Guidelines" about doing your own research, and showing your own efforts.
@teckk. That's not enough. As individual suggested above, the output of cut should be fed to sort -u. I'd also use the -s / --only-delimited option to cut here, just in case.
Besides,
Quote:
Originally Posted by sunlinux
I want to extract only values after jsp?id=
Please note that not all URLs from the top post include jsp, but this may be a misrepresentation on the part of OP.
#!/bin/bash
while IFS='=' read -r url id
do [[ $url == *.jsp\?id ]] && [[ -n $id ]] && a["$id"]=
done <"$file"
printf %s\\n "${!a[@]}"
POSIX shell:
Code:
#!/bin/sh
set --
while IFS='=' read -r url id
do case $url in *.jsp\?id)
[ -n "$id" ] && {
new=true
for i
do [ "$i" -eq "$id" ] && { new=false; break;}
done
$new && set -- "$id" "$@"
}
esac
done <"$file"
IFS='
'; echo "$*"
since this is a programming forum, i assume you are coding this instead of seeking a command line to do it. which language are you using? awk? bash? c? c++? go? java? lua? perl? python? rust? something else? what do you want to happen to lines without "jsp" (such as line 2)?
I want to extract only values after jsp?id= for example from 'jsp?id=1600809955' I want to extract 1600809955 and print it, if any duplicate entry remove while printing
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.