473,842 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get a specific word in a file?

60 New Member
hi,

how can i get the particular line/word in the file.

Ex:
$ cat my_file.txt
1
2
3
4
5
6
7

I want to get the "7" in the file my_file.txt. Tnx.


-coax
Jun 21 '07
15 19679
coaxfiber
60 New Member
Yes, I agree to you.I want to give some apology if I had to overuse this forum for my own benefit. Perhaps I need to concentrate on my work. I hope I could also help some people who also needs some support.. Thanks.
Jun 25 '07 #11
ghostdog74
511 Recognized Expert Contributor
Hi.. I think I almost found exactly what will really answer my question.. What if the third word is not always '8'. How about it will depend on my input?
$Input ID: 6
then it will search for all lines that contain 6 in the 3rd word. Thanks.
then you can do this for example
Expand|Select|Wrap|Line Numbers
  1. echo "Enter input"
  2. read input
  3. awk -v input=$input '$2 == 7 && $3 == input {print }' "file" 
  4.  
Jun 25 '07 #12
coaxfiber
60 New Member
then you can do this for example
Expand|Select|Wrap|Line Numbers
  1. echo "Enter input"
  2. read input
  3. awk -v input=$input '$2 == 7 && $3 == input {print }' "file" 
  4.  
Thank You Sir! This is exactly what I need. I had tried to used the ' -v ' option before but some syntax came to error.

BR,
-coax
Jun 26 '07 #13
marimuthup
1 New Member
with awk or grep how would I get a specific word in a file, rather than a lin.

For example:

File contains lines such as

This is MyTime:00:0450 Secs

I wanna to extract the String where it is between 'MyTime:' and Secs, where I need only the String '00:0450' printed.

Definelty not the entire row.

Could some one help me?
Aug 16 '07 #14
docdiesel
297 Recognized Expert Contributor
with awk or grep how would I get a specific word in a file, rather than a lin. For example:

File contains lines such as
This is MyTime:00:0450 Secs
....
Hi,

perhaps you should've opend a new thread for your question. Anyway, what may fit your needs is a line like this:

Expand|Select|Wrap|Line Numbers
  1.  # read from file, replace 1st ':' with space, then print column #4 only
  2.  sed <inputfile  s/:/\ /  |  awk '{print $4;}'
  3.  
Regards,

Bernd
Aug 16 '07 #15
coaxfiber
60 New Member
with awk or grep how would I get a specific word in a file, rather than a lin.

For example:

File contains lines such as

This is MyTime:00:0450 Secs

I wanna to extract the String where it is between 'MyTime:' and Secs, where I need only the String '00:0450' printed.

Definelty not the entire row.

Could some one help me?

Hi,


Try this one assuming line 'MyTime:00:0450 Secs' is fix and only the numbers are varying,


cut -c 8-14 file.txt

FYI.

-coax
Aug 16 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1637
by: MM | last post by:
Hello, Can anyone help me with this: I would like to use a help functionality in my program, in such way that a specific page (or topic) in the help file (a standard Windows .hlp file) is opened directly without me having to type in the topic or search word by hand. In other words, can I access a specific page in a .hlp file?
1
1546
by: DP | last post by:
hi, i know how to open ms word in access, but is there a way to open a specific file?? i've a created a mail merge letter, and i want to be able to click on a button in access, and it opens that specific document. TIA
5
2767
by: akelly_image | last post by:
Okay, if anyone could toss me some idea's here, please bare with my noobish questions, I just picked up VB2005 Pro about a week ago. ( no prior VB at all ) Here's my issue.. I'm pulling information out of a text file and need to pull specific words out of a string. For example, the text file looks sorta like this:
12
10694
by: Dixie | last post by:
Is there a way to shell to Microsoft Word from Access and load a specific template - using VBA? dixie
6
2353
by: vincent90152900 | last post by:
always get an error message. "Object reference not set to an instance of an object" Can anyone how to solve this? Here is my code. private void CreateNewWordFile(string sourceFileName,string destinationFileName,string stratBookmarkName,string endBookmarkName) { // Declaring the object variables we will need later object varFileName = fileName; object varFalseValue = false;
2
19762
by: Francesco Pietra | last post by:
Please, how to adapt the following script (to delete blank lines) to delete lines containing a specific word, or words? f=open("output.pdb", "r") for line in f: line=line.rstrip() if line: print line f.close()
0
2098
by: Francesco Pietra | last post by:
I forgot to add that the lines to strip are in present case of the type of the following block HETATM 7007 O WAT 446 27.622 34.356 55.205 1.00 0.00 O HETATM 7008 H1 WAT 446 27.436 34.037 56.145 1.00 0.00 H HETATM 7009 H2 WAT 446 27.049 33.827 54.563 1.00 0.00 H occurring in a 300MB file. In present case each three-lines block is followed by line renumbering (7007,
2
2123
by: dpw.asdf | last post by:
I have been searching all over for a solution to this. I am new to Python, so I'm a little lost. Any pointers would be a great help. I have a couple hundred emails that contain data I would like to incorporate into a database or CSV file. I want to search the email for specific text. The emails basically look like this:
3
4364
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right now the way I have this set up, but it's confusing and slow. When they browse for a place to save the reports, they see all of the drives on the terminal server as well as their own client drives. So they're likely to want to choose "My...
3
3185
by: Sevla | last post by:
hello, im having a problem to change a particular word in a line, can´t find where is my mistake also i would like to know how to make this program check automatically if a particular word exists on the line you got to you exchange it or not i didnt find the right condition to do it
0
9870
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10940
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10610
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10670
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7854
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4499
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.